Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Numeric entity with leading 0

  • Loading branch information...
commit 966e19c2e7aa7a605498362f6322038eb87505ec 1 parent 1e640ee
Henry Rawas authored September 14, 2011 isaacs committed September 16, 2011
11  lib/sax.js
@@ -478,17 +478,22 @@ function closeTag (parser) {
478 478
 }
479 479
 
480 480
 function parseEntity (parser) {
481  
-  var entity = parser.entity.toLowerCase(), num, numStr = ""
  481
+  var entity = parser.entity.toLowerCase()
  482
+    , num
  483
+    , numStr = ""
482 484
   if (parser.ENTITIES[entity]) return parser.ENTITIES[entity]
483 485
   if (entity.charAt(0) === "#") {
484 486
     if (entity.charAt(1) === "x") {
485 487
       entity = entity.slice(2)
486  
-      num = parseInt(entity, 16), numStr = num.toString(16)
  488
+      num = parseInt(entity, 16)
  489
+      numStr = num.toString(16)
487 490
     } else {
488 491
       entity = entity.slice(1)
489  
-      num = parseInt(entity, 10), numStr = num.toString(10)
  492
+      num = parseInt(entity, 10)
  493
+      numStr = num.toString(10)
490 494
     }
491 495
   }
  496
+  entity = entity.replace(/^0+/, "")
492 497
   if (numStr.toLowerCase() !== entity) {
493 498
     strictFail(parser, "Invalid character entity")
494 499
     return "&"+parser.entity + ";"
15  test/issue-35.js
... ...
@@ -0,0 +1,15 @@
  1
+// https://github.com/isaacs/sax-js/issues/35
  2
+require(__dirname).test
  3
+  ( { xml : "<xml>&#Xd;&#X0d;\n"+
  4
+            "</xml>"
  5
+
  6
+    , expect :
  7
+      [ [ "opentag", { name: "xml", attributes: {} } ]
  8
+      , [ "text", "\r\r\n" ]
  9
+      , [ "closetag", "xml" ]
  10
+      ]
  11
+    , strict : true
  12
+    , opt : {}
  13
+    }
  14
+  )
  15
+

0 notes on commit 966e19c

Please sign in to comment.
Something went wrong with that request. Please try again.