Permalink
Browse files

Numeric entity with leading 0

  • Loading branch information...
1 parent 1e640ee commit 966e19c2e7aa7a605498362f6322038eb87505ec @HenryRawas HenryRawas committed with isaacs Sep 14, 2011
Showing with 23 additions and 3 deletions.
  1. +8 −3 lib/sax.js
  2. +15 −0 test/issue-35.js
View
11 lib/sax.js
@@ -478,17 +478,22 @@ function closeTag (parser) {
}
function parseEntity (parser) {
- var entity = parser.entity.toLowerCase(), num, numStr = ""
+ var entity = parser.entity.toLowerCase()
+ , num
+ , numStr = ""
if (parser.ENTITIES[entity]) return parser.ENTITIES[entity]
if (entity.charAt(0) === "#") {
if (entity.charAt(1) === "x") {
entity = entity.slice(2)
- num = parseInt(entity, 16), numStr = num.toString(16)
+ num = parseInt(entity, 16)
+ numStr = num.toString(16)
} else {
entity = entity.slice(1)
- num = parseInt(entity, 10), numStr = num.toString(10)
+ num = parseInt(entity, 10)
+ numStr = num.toString(10)
}
}
+ entity = entity.replace(/^0+/, "")
if (numStr.toLowerCase() !== entity) {
strictFail(parser, "Invalid character entity")
return "&"+parser.entity + ";"
View
15 test/issue-35.js
@@ -0,0 +1,15 @@
+// https://github.com/isaacs/sax-js/issues/35
+require(__dirname).test
+ ( { xml : "<xml>&#Xd;&#X0d;\n"+
+ "</xml>"
+
+ , expect :
+ [ [ "opentag", { name: "xml", attributes: {} } ]
+ , [ "text", "\r\r\n" ]
+ , [ "closetag", "xml" ]
+ ]
+ , strict : true
+ , opt : {}
+ }
+ )
+

0 comments on commit 966e19c

Please sign in to comment.