Skip to content

Commit

Permalink
Close #33 Single-hyphens allowed in comments in strict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Aug 1, 2011
1 parent cae7b6f commit 47fa48f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/sax.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,14 +530,19 @@ function write (chunk) {
if (parser.comment) emitNode(parser, "oncomment", parser.comment)
parser.comment = ""
} else {
strictFail(parser, "Invalid comment")
parser.comment += "-" + c
parser.state = S.COMMENT
}
continue

case S.COMMENT_ENDED:
if (c !== ">") strictFail(parser, "Malformed comment")
else parser.state = S.TEXT
if (c !== ">") {
strictFail(parser, "Malformed comment")
// allow <!-- blah -- bloo --> in non-strict mode,
// which is a comment of " blah -- bloo "
parser.comment += "--" + c
parser.state = S.COMMENT
} else parser.state = S.TEXT
continue

case S.CDATA:
Expand Down
24 changes: 24 additions & 0 deletions test/issue-30.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// https://github.com/isaacs/sax-js/issues/33
require(__dirname).test
( { xml : "<xml>\n"+
"<!-- \n"+
" comment with a single dash- in it\n"+
"-->\n"+
"<data/>\n"+
"</xml>"

, expect :
[ [ "opentag", { name: "xml", attributes: {} } ]
, [ "text", "\n" ]
, [ "comment", " \n comment with a single dash- in it\n" ]
, [ "text", "\n" ]
, [ "opentag", { name: "data", attributes: {} } ]
, [ "closetag", "data" ]
, [ "text", "\n" ]
, [ "closetag", "xml" ]
]
, strict : true
, opt : {}
}
)

0 comments on commit 47fa48f

Please sign in to comment.