From 5c44c134651d71e6733a94e28d671667b54051c1 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Thu, 22 Nov 2012 10:07:19 +0100 Subject: [PATCH] Make sure readInt doesn't try to read past len, if given Issue #15 --- acorn.js | 2 +- index.html | 2 +- test/tests.js | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/acorn.js b/acorn.js index 7785748cab..732c42c92c 100644 --- a/acorn.js +++ b/acorn.js @@ -673,7 +673,7 @@ function readInt(radix, len) { var start = tokPos, total = 0; - for (;;) { + for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) { var code = input.charCodeAt(tokPos), val; if (code >= 97) val = code - 97 + 10; // a else if (code >= 65) val = code - 65 + 10; // A diff --git a/index.html b/index.html index 625d5a6ccb..aae57ab37e 100644 --- a/index.html +++ b/index.html @@ -451,7 +451,7 @@ here (don't ask).

were read, the integer value otherwise. When len is given, this will return null unless the integer has exactly len digits.

  function readInt(radix, len) {
     var start = tokPos, total = 0;
-    for (;;) {
+    for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
       var code = input.charCodeAt(tokPos), val;
       if (code >= 97) val = code - 97 + 10; // a
       else if (code >= 65) val = code - 65 + 10; // A
diff --git a/test/tests.js b/test/tests.js
index e571d49670..ac69bb6381 100644
--- a/test/tests.js
+++ b/test/tests.js
@@ -26016,6 +26016,19 @@ test("a\u2028b", {
   ]
 });
 
+test("'a\\u0026b'", {
+  type: "Program",
+  body: [
+    {
+      type: "ExpressionStatement",
+      expression: {
+        type: "Literal",
+        value: "a\u0026b"
+      }
+    }
+  ]
+});
+
 // Failure tests
 
 testFail("{",