Bug 51724 - In strict mode string literals should allow \0, but disallow \8 and \9.
authorbarraclough@apple.com <barraclough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Dec 2010 00:00:24 +0000 (00:00 +0000)
committerbarraclough@apple.com <barraclough@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Dec 2010 00:00:24 +0000 (00:00 +0000)
Reviewed by Sam Weinig.

JavaScriptCore:

* parser/Lexer.cpp:
(JSC::Lexer::parseString):

LayoutTests:

* fast/js/numeric-escapes-in-string-literals-expected.txt: Added.
* fast/js/numeric-escapes-in-string-literals.html: Added.
* fast/js/script-tests/numeric-escapes-in-string-literals.js: Added.
(test):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@74767 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/ChangeLog
JavaScriptCore/parser/Lexer.cpp
LayoutTests/ChangeLog
LayoutTests/fast/js/numeric-escapes-in-string-literals-expected.txt [new file with mode: 0644]
LayoutTests/fast/js/numeric-escapes-in-string-literals.html [new file with mode: 0644]
LayoutTests/fast/js/script-tests/numeric-escapes-in-string-literals.js [new file with mode: 0644]

index c868f29..7e117ba 100644 (file)
@@ -1,3 +1,12 @@
+2010-12-29  Gavin Barraclough  <barraclough@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Bug 51724 - In strict mode string literals should allow \0, but disallow \8 and \9.
+
+        * parser/Lexer.cpp:
+        (JSC::Lexer::parseString):
+
 2010-12-29  Helder Correia  <helder@sencha.com>
 
         Reviewed by Eric Seidel.
index b443561..ff7079f 100644 (file)
@@ -492,10 +492,15 @@ ALWAYS_INLINE bool Lexer::parseString(JSTokenData* lvalp, bool strictMode)
                     record16('u');
                 else // Only stringQuoteCharacter allowed after \u
                     return false;
-            } else if (isASCIIOctalDigit(m_current)) {
-                // Octal character sequences
-                if (strictMode)
+            } else if (strictMode && isASCIIDigit(m_current)) {
+                // The only valid numeric escape in strict mode is '\0', and this must not be followed by a decimal digit.
+                int character1 = m_current;
+                shift();
+                if (character1 != '0' || isASCIIDigit(m_current))
                     return false;
+                record16(0);
+            } else if (!strictMode && isASCIIOctalDigit(m_current)) {
+                // Octal character sequences
                 int character1 = m_current;
                 shift();
                 if (isASCIIOctalDigit(m_current)) {
index 15673c5..2a79630 100644 (file)
@@ -1,3 +1,14 @@
+2010-12-29  Gavin Barraclough  <barraclough@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Bug 51724 - In strict mode string literals should allow \0, but disallow \8 and \9.
+
+        * fast/js/numeric-escapes-in-string-literals-expected.txt: Added.
+        * fast/js/numeric-escapes-in-string-literals.html: Added.
+        * fast/js/script-tests/numeric-escapes-in-string-literals.js: Added.
+        (test):
+
 2010-12-29  Mihai Parparita  <mihaip@chromium.org>
 
         Unreviewed Chromium expectations update. Mark another test as flaky.
diff --git a/LayoutTests/fast/js/numeric-escapes-in-string-literals-expected.txt b/LayoutTests/fast/js/numeric-escapes-in-string-literals-expected.txt
new file mode 100644 (file)
index 0000000..922bf76
--- /dev/null
@@ -0,0 +1,45 @@
+Test numeric escapes in string literals - https://bugs.webkit.org/show_bug.cgi?id=51724
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS eval(stringLiteral) is nonStrictResult
+PASS eval(stringLiteral) is strictResult
+PASS eval(stringLiteral) is nonStrictResult
+PASS eval(stringLiteral) threw exception SyntaxError: Parse error.
+PASS eval(stringLiteral) is nonStrictResult
+PASS eval(stringLiteral) threw exception SyntaxError: Parse error.
+PASS eval(stringLiteral) is nonStrictResult
+PASS eval(stringLiteral) threw exception SyntaxError: Parse error.
+PASS eval(stringLiteral) is nonStrictResult
+PASS eval(stringLiteral) threw exception SyntaxError: Parse error.
+PASS eval(stringLiteral) is nonStrictResult
+PASS eval(stringLiteral) threw exception SyntaxError: Parse error.
+PASS eval(stringLiteral) is nonStrictResult
+PASS eval(stringLiteral) threw exception SyntaxError: Parse error.
+PASS eval(stringLiteral) is nonStrictResult
+PASS eval(stringLiteral) threw exception SyntaxError: Parse error.
+PASS eval(stringLiteral) is nonStrictResult
+PASS eval(stringLiteral) threw exception SyntaxError: Parse error.
+PASS eval(stringLiteral) is nonStrictResult
+PASS eval(stringLiteral) threw exception SyntaxError: Parse error.
+PASS eval(stringLiteral) is nonStrictResult
+PASS eval(stringLiteral) threw exception SyntaxError: Parse error.
+PASS eval(stringLiteral) is nonStrictResult
+PASS eval(stringLiteral) threw exception SyntaxError: Parse error.
+PASS eval(stringLiteral) is nonStrictResult
+PASS eval(stringLiteral) threw exception SyntaxError: Parse error.
+PASS eval(stringLiteral) is nonStrictResult
+PASS eval(stringLiteral) threw exception SyntaxError: Parse error.
+PASS eval(stringLiteral) is nonStrictResult
+PASS eval(stringLiteral) threw exception SyntaxError: Parse error.
+PASS eval(stringLiteral) is nonStrictResult
+PASS eval(stringLiteral) threw exception SyntaxError: Parse error.
+PASS eval(stringLiteral) is nonStrictResult
+PASS eval(stringLiteral) threw exception SyntaxError: Parse error.
+PASS eval(stringLiteral) is nonStrictResult
+PASS eval(stringLiteral) threw exception SyntaxError: Parse error.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/js/numeric-escapes-in-string-literals.html b/LayoutTests/fast/js/numeric-escapes-in-string-literals.html
new file mode 100644 (file)
index 0000000..aeef8ea
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="resources/js-test-style.css">
+<script src="resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/numeric-escapes-in-string-literals.js"></script>
+<script src="resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/js/script-tests/numeric-escapes-in-string-literals.js b/LayoutTests/fast/js/script-tests/numeric-escapes-in-string-literals.js
new file mode 100644 (file)
index 0000000..3ba392e
--- /dev/null
@@ -0,0 +1,48 @@
+description(
+"Test numeric escapes in string literals - https://bugs.webkit.org/show_bug.cgi?id=51724"
+);
+
+function test(_stringLiteral, _nonStrictResult, _strictResult)
+{
+    stringLiteral = '"' + _stringLiteral + '"';
+    nonStrictResult = _nonStrictResult;
+    shouldBe("eval(stringLiteral)", "nonStrictResult");
+
+    stringLiteral = '"use strict"; ' + stringLiteral;
+    if (_strictResult) {
+        strictResult = _strictResult;
+        shouldBe("eval(stringLiteral)", "strictResult");
+    } else
+        shouldThrow("eval(stringLiteral)");
+}
+
+// Tests for single digit octal and decimal escapes.
+// In non-strict mode 0-7 are octal escapes, 8-9 are NonEscapeCharacters.
+// In strict mode only "\0" is permitted.
+test("\\0", "\x00", "\x00");
+test("\\1", "\x01");
+test("\\7", "\x07");
+test("\\8", "8");
+test("\\9", "9");
+
+// Tests for multi-digit octal values outside strict mode;
+// Octal literals may be 1-3 digits long.  In strict more all multi-digit sequences are illegal.
+test("\\00", "\x00");
+test("\\000", "\x00");
+test("\\0000", "\x000");
+
+test("\\01", "\x01");
+test("\\001", "\x01");
+test("\\0001", "\x001");
+
+test("\\10", "\x08");
+test("\\100", "\x40");
+test("\\1000", "\x400");
+
+test("\\19", "\x019");
+test("\\109", "\x089");
+test("\\1009", "\x409");
+
+test("\\99", "99");
+
+var successfullyParsed = true;