Title: [255544] trunk
Revision
255544
Author
[email protected]
Date
2020-02-01 16:20:04 -0800 (Sat, 01 Feb 2020)

Log Message

Non-alphabetical \c escapes should be syntax errors in Unicode patterns only
https://bugs.webkit.org/show_bug.cgi?id=207091

Reviewed by Darin Adler.

JSTests:

* test262/expectations.yaml: Mark 4 test cases as passing.

Source/_javascript_Core:

This change adds SyntaxError for non-alphabetical and identity \c escapes
in Unicode patterns, aligning JSC with V8 and SpiderMonkey.

Grammar: https://tc39.es/ecma262/#prod-annexB-ClassEscape
(/u flag precludes the use of ClassControlLetter)

* yarr/YarrErrorCode.cpp:
(JSC::Yarr::errorMessage):
(JSC::Yarr::errorToThrow):
* yarr/YarrErrorCode.h:
* yarr/YarrParser.h:
(JSC::Yarr::Parser::parseEscape):

LayoutTests:

* js/regexp-unicode-expected.txt:
* js/script-tests/regexp-unicode.js:

Modified Paths

Diff

Modified: trunk/JSTests/ChangeLog (255543 => 255544)


--- trunk/JSTests/ChangeLog	2020-02-01 22:26:34 UTC (rev 255543)
+++ trunk/JSTests/ChangeLog	2020-02-02 00:20:04 UTC (rev 255544)
@@ -1,3 +1,12 @@
+2020-02-01  Alexey Shvayka  <[email protected]>
+
+        Non-alphabetical \c escapes should be syntax errors in Unicode patterns only
+        https://bugs.webkit.org/show_bug.cgi?id=207091
+
+        Reviewed by Darin Adler.
+
+        * test262/expectations.yaml: Mark 4 test cases as passing.
+
 2020-01-31  Saam Barati  <[email protected]>
 
         Unreviewed. Don't dump disassembly in test.

Modified: trunk/JSTests/test262/expectations.yaml (255543 => 255544)


--- trunk/JSTests/test262/expectations.yaml	2020-02-01 22:26:34 UTC (rev 255543)
+++ trunk/JSTests/test262/expectations.yaml	2020-02-02 00:20:04 UTC (rev 255544)
@@ -1577,11 +1577,8 @@
   default: "Test262Error: Invalid IdentityEscape in AtomEscape: '\\"
   strict mode: "Test262Error: Invalid IdentityEscape in AtomEscape: '\\"
 test/built-ins/RegExp/unicode_restricted_identity_escape_alpha.js:
-  default: "Test262Error: IdentityEscape in AtomEscape: 'c' Expected a SyntaxError to be thrown but no exception was thrown at all"
-  strict mode: "Test262Error: IdentityEscape in AtomEscape: 'c' Expected a SyntaxError to be thrown but no exception was thrown at all"
-test/built-ins/RegExp/unicode_restricted_identity_escape_c.js:
-  default: 'Test262Error: Expected a SyntaxError to be thrown but no exception was thrown at all'
-  strict mode: 'Test262Error: Expected a SyntaxError to be thrown but no exception was thrown at all'
+  default: "Test262Error: IdentityEscape in AtomEscape: 'k' Expected a SyntaxError to be thrown but no exception was thrown at all"
+  strict mode: "Test262Error: IdentityEscape in AtomEscape: 'k' Expected a SyntaxError to be thrown but no exception was thrown at all"
 test/built-ins/RegExp/unicode_restricted_octal_escape.js:
   default: 'Test262Error: RegExp("[\1]", "u"):  Expected a SyntaxError to be thrown but no exception was thrown at all'
   strict mode: 'Test262Error: RegExp("[\1]", "u"):  Expected a SyntaxError to be thrown but no exception was thrown at all'
@@ -3372,9 +3369,6 @@
 test/language/literals/regexp/u-dec-esc.js:
   default: 'Test262: This statement should not be evaluated.'
   strict mode: 'Test262: This statement should not be evaluated.'
-test/language/literals/regexp/u-invalid-class-escape.js:
-  default: 'Test262: This statement should not be evaluated.'
-  strict mode: 'Test262: This statement should not be evaluated.'
 test/language/literals/regexp/u-invalid-legacy-octal-escape.js:
   default: 'Test262: This statement should not be evaluated.'
   strict mode: 'Test262: This statement should not be evaluated.'

Modified: trunk/LayoutTests/ChangeLog (255543 => 255544)


--- trunk/LayoutTests/ChangeLog	2020-02-01 22:26:34 UTC (rev 255543)
+++ trunk/LayoutTests/ChangeLog	2020-02-02 00:20:04 UTC (rev 255544)
@@ -1,3 +1,13 @@
+2020-02-01  Alexey Shvayka  <[email protected]>
+
+        Non-alphabetical \c escapes should be syntax errors in Unicode patterns only
+        https://bugs.webkit.org/show_bug.cgi?id=207091
+
+        Reviewed by Darin Adler.
+
+        * js/regexp-unicode-expected.txt:
+        * js/script-tests/regexp-unicode.js:
+
 2020-01-31  Jacob Uphoff  <[email protected]>
 
         Flaky Test: imported/w3c/web-platform-tests/websockets/cookies/007.html

Modified: trunk/LayoutTests/js/regexp-unicode-expected.txt (255543 => 255544)


--- trunk/LayoutTests/js/regexp-unicode-expected.txt	2020-02-01 22:26:34 UTC (rev 255543)
+++ trunk/LayoutTests/js/regexp-unicode-expected.txt	2020-02-02 00:20:04 UTC (rev 255544)
@@ -168,6 +168,7 @@
 PASS /{/u threw exception SyntaxError: Invalid regular _expression_: incomplete {} quantifier for Unicode pattern.
 PASS /[a-\d]/u threw exception SyntaxError: Invalid regular _expression_: invalid range in character class for Unicode pattern.
 PASS /]/u threw exception SyntaxError: Invalid regular _expression_: unmatched ] or } bracket for Unicode pattern.
+PASS /\c9/u threw exception SyntaxError: Invalid regular _expression_: invalid \c escape for Unicode pattern.
 PASS r = new RegExp("\\-", "u") threw exception SyntaxError: Invalid regular _expression_: invalid escaped character for Unicode pattern.
 PASS r = new RegExp("\\a", "u") threw exception SyntaxError: Invalid regular _expression_: invalid escaped character for Unicode pattern.
 PASS r = new RegExp("[\\a]", "u") threw exception SyntaxError: Invalid regular _expression_: invalid escaped character for Unicode pattern.

Modified: trunk/LayoutTests/js/script-tests/regexp-unicode.js (255543 => 255544)


--- trunk/LayoutTests/js/script-tests/regexp-unicode.js	2020-02-01 22:26:34 UTC (rev 255543)
+++ trunk/LayoutTests/js/script-tests/regexp-unicode.js	2020-02-02 00:20:04 UTC (rev 255544)
@@ -233,6 +233,7 @@
 shouldThrow('/{/u', '"SyntaxError: Invalid regular _expression_: incomplete {} quantifier for Unicode pattern"');
 shouldThrow('/[a-\\d]/u', '"SyntaxError: Invalid regular _expression_: invalid range in character class for Unicode pattern"');
 shouldThrow('/]/u', '"SyntaxError: Invalid regular _expression_: unmatched ] or } bracket for Unicode pattern"');
+shouldThrow('/\\c9/u', '"SyntaxError: Invalid regular _expression_: invalid \\\\c escape for Unicode pattern"');
 
 var invalidEscapeException = "SyntaxError: Invalid regular _expression_: invalid escaped character for Unicode pattern";
 var newRegExp;

Modified: trunk/Source/_javascript_Core/ChangeLog (255543 => 255544)


--- trunk/Source/_javascript_Core/ChangeLog	2020-02-01 22:26:34 UTC (rev 255543)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-02-02 00:20:04 UTC (rev 255544)
@@ -1,3 +1,23 @@
+2020-02-01  Alexey Shvayka  <[email protected]>
+
+        Non-alphabetical \c escapes should be syntax errors in Unicode patterns only
+        https://bugs.webkit.org/show_bug.cgi?id=207091
+
+        Reviewed by Darin Adler.
+
+        This change adds SyntaxError for non-alphabetical and identity \c escapes
+        in Unicode patterns, aligning JSC with V8 and SpiderMonkey.
+
+        Grammar: https://tc39.es/ecma262/#prod-annexB-ClassEscape
+        (/u flag precludes the use of ClassControlLetter)
+
+        * yarr/YarrErrorCode.cpp:
+        (JSC::Yarr::errorMessage):
+        (JSC::Yarr::errorToThrow):
+        * yarr/YarrErrorCode.h:
+        * yarr/YarrParser.h:
+        (JSC::Yarr::Parser::parseEscape):
+
 2020-01-31  Yusuke Suzuki  <[email protected]>
 
         [JSC] Hold StructureID instead of Structure* in PolyProtoAccessChain and DFG::CommonData

Modified: trunk/Source/_javascript_Core/yarr/YarrErrorCode.cpp (255543 => 255544)


--- trunk/Source/_javascript_Core/yarr/YarrErrorCode.cpp	2020-02-01 22:26:34 UTC (rev 255543)
+++ trunk/Source/_javascript_Core/yarr/YarrErrorCode.cpp	2020-02-02 00:20:04 UTC (rev 255544)
@@ -54,6 +54,7 @@
         REGEXP_ERROR_PREFIX "invalid Unicode {} escape",                            // InvalidUnicodeEscape
         REGEXP_ERROR_PREFIX "invalid backreference for Unicode pattern",            // InvalidBackreference
         REGEXP_ERROR_PREFIX "invalid escaped character for Unicode pattern",        // InvalidIdentityEscape
+        REGEXP_ERROR_PREFIX "invalid \\c escape for Unicode pattern",               // InvalidControlLetterEscape
         REGEXP_ERROR_PREFIX "invalid property _expression_",                          // InvalidUnicodePropertyExpression
         REGEXP_ERROR_PREFIX "too many nested disjunctions",                         // TooManyDisjunctions
         REGEXP_ERROR_PREFIX "pattern exceeds string length limits",                 // OffsetTooLarge
@@ -87,6 +88,7 @@
     case ErrorCode::InvalidUnicodeEscape:
     case ErrorCode::InvalidBackreference:
     case ErrorCode::InvalidIdentityEscape:
+    case ErrorCode::InvalidControlLetterEscape:
     case ErrorCode::InvalidUnicodePropertyExpression:
     case ErrorCode::OffsetTooLarge:
     case ErrorCode::InvalidRegularExpressionFlags:

Modified: trunk/Source/_javascript_Core/yarr/YarrErrorCode.h (255543 => 255544)


--- trunk/Source/_javascript_Core/yarr/YarrErrorCode.h	2020-02-01 22:26:34 UTC (rev 255543)
+++ trunk/Source/_javascript_Core/yarr/YarrErrorCode.h	2020-02-02 00:20:04 UTC (rev 255544)
@@ -53,6 +53,7 @@
     InvalidUnicodeEscape,
     InvalidBackreference,
     InvalidIdentityEscape,
+    InvalidControlLetterEscape,
     InvalidUnicodePropertyExpression,
     TooManyDisjunctions,
     OffsetTooLarge,

Modified: trunk/Source/_javascript_Core/yarr/YarrParser.h (255543 => 255544)


--- trunk/Source/_javascript_Core/yarr/YarrParser.h	2020-02-01 22:26:34 UTC (rev 255543)
+++ trunk/Source/_javascript_Core/yarr/YarrParser.h	2020-02-02 00:20:04 UTC (rev 255544)
@@ -397,12 +397,28 @@
             if (!atEndOfPattern()) {
                 int control = consume();
 
-                // To match Firefox, inside a character class, we also accept numbers and '_' as control characters.
-                if (inCharacterClass ? WTF::isASCIIAlphanumeric(control) || (control == '_') : WTF::isASCIIAlpha(control)) {
+                if (WTF::isASCIIAlpha(control)) {
                     delegate.atomPatternCharacter(control & 0x1f);
                     break;
                 }
+
+                if (m_isUnicode) {
+                    m_errorCode = ErrorCode::InvalidControlLetterEscape;
+                    break;
+                }
+
+                // https://tc39.es/ecma262/#prod-annexB-ClassControlLetter
+                if (inCharacterClass && (WTF::isASCIIDigit(control) || control == '_')) {
+                    delegate.atomPatternCharacter(control & 0x1f);
+                    break;
+                }
             }
+
+            if (m_isUnicode) {
+                m_errorCode = ErrorCode::InvalidIdentityEscape;
+                break;
+            }
+
             restoreState(state);
             delegate.atomPatternCharacter('\\');
             break;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to