Title: [235882] trunk
Revision
235882
Author
msab...@apple.com
Date
2018-09-10 21:53:56 -0700 (Mon, 10 Sep 2018)

Log Message

Test262 failure with Named Capture Groups - using a reference before the group is defined
https://bugs.webkit.org/show_bug.cgi?id=189407

Reviewed by Alex Christensen.

JSTests:

Re-enabled previously failing test.

* test262.yaml:
* test262/expectations.yaml:

Source/_javascript_Core:

Added code to save the named forward references we see during parsing and validating that
they are all present when parsing the RegExp is complete.  If there are unnamed references,
we reparse with some variation of behavior.  Just like for numeric references, the
behavior is different depending on whether or not the unicode (u flag) is present.  
For non-unicode patterns, we treat the \k<...> as a literal pattern.  For a unicode 
pattern we throw an exception.

Did some refactoring, renaming YarrPattern::reset() and YarrPatternConstructor::reset()
resetForReparsing() as that is the only use for those methods.  Also changed
all the delegate methods that take a String to take a const String& to eliminate
copy churn.

* yarr/YarrParser.h:
(JSC::Yarr::Parser::CharacterClassParserDelegate::atomNamedBackReference):
(JSC::Yarr::Parser::CharacterClassParserDelegate::isValidNamedForwardReference):
(JSC::Yarr::Parser::CharacterClassParserDelegate::atomNamedForwardReference):
(JSC::Yarr::Parser::parseEscape):
* yarr/YarrPattern.cpp:
(JSC::Yarr::YarrPatternConstructor::resetForReparsing):
(JSC::Yarr::YarrPatternConstructor::saveUnmatchedNamedForwardReferences):
(JSC::Yarr::YarrPatternConstructor::atomNamedBackReference):
(JSC::Yarr::YarrPatternConstructor::isValidNamedForwardReference):
(JSC::Yarr::YarrPatternConstructor::atomNamedForwardReference):
(JSC::Yarr::YarrPattern::compile):
(JSC::Yarr::YarrPatternConstructor::reset): Deleted.
* yarr/YarrPattern.h:
(JSC::Yarr::YarrPattern::resetForReparsing):
(JSC::Yarr::YarrPattern::containsIllegalNamedForwardReferences):
(JSC::Yarr::YarrPattern::reset): Deleted.
* yarr/YarrSyntaxChecker.cpp:
(JSC::Yarr::SyntaxChecker::atomNamedBackReference):
(JSC::Yarr::SyntaxChecker::isValidNamedForwardReference):
(JSC::Yarr::SyntaxChecker::atomNamedForwardReference):

Source/WebCore:

Created new delegate stubs for RegExp parsing.  These are not needed for the URL filtering
use cases.  Also changed all the delegate methods that take a String to take 
const String& to eliminate copy churn.

Updated TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp.

* contentextensions/URLFilterParser.cpp:
(WebCore::ContentExtensions::PatternParser::atomNamedBackReference):
(WebCore::ContentExtensions::PatternParser::isValidNamedForwardReference):
(WebCore::ContentExtensions::PatternParser::atomNamedForwardReference):
(WebCore::ContentExtensions::URLFilterParser::statusString):
* contentextensions/URLFilterParser.h:

Tools:

Updated test.

* TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
(TestWebKitAPI::TEST_F):

LayoutTests:

Updated tests.

* js/regexp-named-capture-groups-expected.txt:
* js/script-tests/regexp-named-capture-groups.js:

Modified Paths

Diff

Modified: trunk/JSTests/ChangeLog (235881 => 235882)


--- trunk/JSTests/ChangeLog	2018-09-11 03:59:41 UTC (rev 235881)
+++ trunk/JSTests/ChangeLog	2018-09-11 04:53:56 UTC (rev 235882)
@@ -1,3 +1,15 @@
+2018-09-10  Michael Saboff  <msab...@apple.com>
+
+        Test262 failure with Named Capture Groups - using a reference before the group is defined
+        https://bugs.webkit.org/show_bug.cgi?id=189407
+
+        Reviewed by Alex Christensen.
+
+        Re-enabled previously failing test.
+
+        * test262.yaml:
+        * test262/expectations.yaml:
+
 2018-09-08  Yusuke Suzuki  <utatane....@gmail.com>
 
         [JSC] Remove loadModule function in jsc.cpp

Modified: trunk/JSTests/test262/expectations.yaml (235881 => 235882)


--- trunk/JSTests/test262/expectations.yaml	2018-09-11 03:59:41 UTC (rev 235881)
+++ trunk/JSTests/test262/expectations.yaml	2018-09-11 04:53:56 UTC (rev 235882)
@@ -1122,9 +1122,6 @@
 test/built-ins/RegExp/named-groups/non-unicode-malformed.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'
-test/built-ins/RegExp/named-groups/non-unicode-references.js:
-  default: "TypeError: null is not an object (evaluating 'b.length')"
-  strict mode: "TypeError: null is not an object (evaluating 'b.length')"
 test/built-ins/RegExp/named-groups/string-replace-nocaptures.js:
   default: 'Test262Error: Expected SameValue(«$<snd>$<fst>cd», «$<$<fst>cd») to be true'
   strict mode: 'Test262Error: Expected SameValue(«$<snd>$<fst>cd», «$<$<fst>cd») to be true'
@@ -1134,9 +1131,6 @@
 test/built-ins/RegExp/named-groups/unicode-property-names.js:
   default: 'SyntaxError: Invalid regular _expression_: invalid group specifier name'
   strict mode: 'SyntaxError: Invalid regular _expression_: invalid group specifier name'
-test/built-ins/RegExp/named-groups/unicode-references.js:
-  default: 'SyntaxError: Invalid regular _expression_: invalid backreference for unicode pattern'
-  strict mode: 'SyntaxError: Invalid regular _expression_: invalid backreference for unicode pattern'
 test/built-ins/RegExp/proto-from-ctor-realm.js:
   default: 'Test262Error: Expected SameValue(«/(?:)/», «/(?:)/») to be true'
   strict mode: 'Test262Error: Expected SameValue(«/(?:)/», «/(?:)/») to be true'

Modified: trunk/JSTests/test262.yaml (235881 => 235882)


--- trunk/JSTests/test262.yaml	2018-09-11 03:59:41 UTC (rev 235881)
+++ trunk/JSTests/test262.yaml	2018-09-11 04:53:56 UTC (rev 235882)
@@ -42180,9 +42180,9 @@
 - path: test262/test/built-ins/RegExp/named-groups/non-unicode-property-names.js
   cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js", "../../../../harness/compareArray.js"], [:strict]
 - path: test262/test/built-ins/RegExp/named-groups/non-unicode-references.js
-  cmd: runTest262 :fail, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js", "../../../../harness/compareArray.js"], []
+  cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js", "../../../../harness/compareArray.js"], []
 - path: test262/test/built-ins/RegExp/named-groups/non-unicode-references.js
-  cmd: runTest262 :fail, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js", "../../../../harness/compareArray.js"], [:strict]
+  cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js", "../../../../harness/compareArray.js"], [:strict]
 - path: test262/test/built-ins/RegExp/named-groups/string-replace-escaped.js
   cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], []
 - path: test262/test/built-ins/RegExp/named-groups/string-replace-escaped.js
@@ -42224,9 +42224,9 @@
 - path: test262/test/built-ins/RegExp/named-groups/unicode-property-names.js
   cmd: runTest262 :fail, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], [:strict]
 - path: test262/test/built-ins/RegExp/named-groups/unicode-references.js
-  cmd: runTest262 :fail, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js", "../../../../harness/compareArray.js"], []
+  cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js", "../../../../harness/compareArray.js"], []
 - path: test262/test/built-ins/RegExp/named-groups/unicode-references.js
-  cmd: runTest262 :fail, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js", "../../../../harness/compareArray.js"], [:strict]
+  cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js", "../../../../harness/compareArray.js"], [:strict]
 - path: test262/test/built-ins/RegExp/property-escapes/binary-properties-with-value.js
   cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], []
 - path: test262/test/built-ins/RegExp/property-escapes/binary-properties-with-value.js

Modified: trunk/LayoutTests/ChangeLog (235881 => 235882)


--- trunk/LayoutTests/ChangeLog	2018-09-11 03:59:41 UTC (rev 235881)
+++ trunk/LayoutTests/ChangeLog	2018-09-11 04:53:56 UTC (rev 235882)
@@ -1,3 +1,15 @@
+2018-09-10  Michael Saboff  <msab...@apple.com>
+
+        Test262 failure with Named Capture Groups - using a reference before the group is defined
+        https://bugs.webkit.org/show_bug.cgi?id=189407
+
+        Reviewed by Alex Christensen.
+
+        Updated tests.
+
+        * js/regexp-named-capture-groups-expected.txt:
+        * js/script-tests/regexp-named-capture-groups.js:
+
 2018-09-10  Ryosuke Niwa  <rn...@webkit.org>
 
         Update shadow DOM and custom elements tests

Modified: trunk/LayoutTests/js/regexp-named-capture-groups-expected.txt (235881 => 235882)


--- trunk/LayoutTests/js/regexp-named-capture-groups-expected.txt	2018-09-11 03:59:41 UTC (rev 235881)
+++ trunk/LayoutTests/js/regexp-named-capture-groups-expected.txt	2018-09-11 04:53:56 UTC (rev 235882)
@@ -61,6 +61,12 @@
 PASS let r = new RegExp("/(?<g𐆛oupName1>abc)/u") threw exception SyntaxError: Invalid regular _expression_: invalid group specifier name.
 PASS let r = new RegExp("/(?<‌groupName1>abc)/u") threw exception SyntaxError: Invalid regular _expression_: invalid group specifier name.
 PASS let r = new RegExp("/(?<‍groupName1>abc)/u") threw exception SyntaxError: Invalid regular _expression_: invalid group specifier name.
+PASS "XzzXzz".match(/\k<z>X(?<z>z*)X\k<z>/) is ["XzzXzz", "zz"]
+PASS "XzzXzz".match(/\k<z>X(?<z>z*)X\k<z>/u) is ["XzzXzz", "zz"]
+PASS "1122332211".match(/\k<ones>\k<twos>\k<threes>(?<ones>1*)(?<twos>2*)(?<threes>3*)\k<threes>\k<twos>\k<ones>/) is ["1122332211", "11", "22", "3"]
+PASS "1122332211".match(/\k<ones>\k<twos>\k<threes>(?<ones>1*)(?<twos>2*)(?<threes>3*)\k<threes>\k<twos>\k<ones>/u) is ["1122332211", "11", "22", "3"]
+PASS "\k<z>XzzX".match(/\k<z>X(z*)X/) is ["k<z>XzzX", "zz"]
+PASS "\k<z>XzzX".match(/\k<z>X(z*)X/u) threw exception SyntaxError: Invalid regular _expression_: invalid backreference for unicode pattern.
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/js/script-tests/regexp-named-capture-groups.js (235881 => 235882)


--- trunk/LayoutTests/js/script-tests/regexp-named-capture-groups.js	2018-09-11 03:59:41 UTC (rev 235881)
+++ trunk/LayoutTests/js/script-tests/regexp-named-capture-groups.js	2018-09-11 04:53:56 UTC (rev 235882)
@@ -104,3 +104,13 @@
 shouldThrow('let r = new RegExp("/(?<\u200cgroupName1>abc)/u")', '"SyntaxError: Invalid regular _expression_: invalid group specifier name"');
 shouldThrow('let r = new RegExp("/(?<\u200dgroupName1>abc)/u")', '"SyntaxError: Invalid regular _expression_: invalid group specifier name"');
 
+// Check the named forward references work
+shouldBe('"XzzXzz".match(/\\\k<z>X(?<z>z*)X\\\k<z>/)', '["XzzXzz", "zz"]');
+shouldBe('"XzzXzz".match(/\\\k<z>X(?<z>z*)X\\\k<z>/u)', '["XzzXzz", "zz"]');
+shouldBe('"1122332211".match(/\\\k<ones>\\\k<twos>\\\k<threes>(?<ones>1*)(?<twos>2*)(?<threes>3*)\\\k<threes>\\\k<twos>\\\k<ones>/)', '["1122332211", "11", "22", "3"]');
+shouldBe('"1122332211".match(/\\\k<ones>\\\k<twos>\\\k<threes>(?<ones>1*)(?<twos>2*)(?<threes>3*)\\\k<threes>\\\k<twos>\\\k<ones>/u)', '["1122332211", "11", "22", "3"]');
+
+// Check that a named forward reference for a non-existent named capture
+// matches for non-unicode patterns and throws for unicode patterns.
+shouldBe('"\\\k<z>XzzX".match(/\\\k<z>X(z*)X/)', '["k<z>XzzX", "zz"]');
+shouldThrow('"\\\k<z>XzzX".match(/\\\k<z>X(z*)X/u)', '"SyntaxError: Invalid regular _expression_: invalid backreference for unicode pattern"');

Modified: trunk/Source/_javascript_Core/ChangeLog (235881 => 235882)


--- trunk/Source/_javascript_Core/ChangeLog	2018-09-11 03:59:41 UTC (rev 235881)
+++ trunk/Source/_javascript_Core/ChangeLog	2018-09-11 04:53:56 UTC (rev 235882)
@@ -1,3 +1,44 @@
+2018-09-10  Michael Saboff  <msab...@apple.com>
+
+        Test262 failure with Named Capture Groups - using a reference before the group is defined
+        https://bugs.webkit.org/show_bug.cgi?id=189407
+
+        Reviewed by Alex Christensen.
+
+        Added code to save the named forward references we see during parsing and validating that
+        they are all present when parsing the RegExp is complete.  If there are unnamed references,
+        we reparse with some variation of behavior.  Just like for numeric references, the
+        behavior is different depending on whether or not the unicode (u flag) is present.  
+        For non-unicode patterns, we treat the \k<...> as a literal pattern.  For a unicode 
+        pattern we throw an exception.
+
+        Did some refactoring, renaming YarrPattern::reset() and YarrPatternConstructor::reset()
+        resetForReparsing() as that is the only use for those methods.  Also changed
+        all the delegate methods that take a String to take a const String& to eliminate
+        copy churn.
+
+        * yarr/YarrParser.h:
+        (JSC::Yarr::Parser::CharacterClassParserDelegate::atomNamedBackReference):
+        (JSC::Yarr::Parser::CharacterClassParserDelegate::isValidNamedForwardReference):
+        (JSC::Yarr::Parser::CharacterClassParserDelegate::atomNamedForwardReference):
+        (JSC::Yarr::Parser::parseEscape):
+        * yarr/YarrPattern.cpp:
+        (JSC::Yarr::YarrPatternConstructor::resetForReparsing):
+        (JSC::Yarr::YarrPatternConstructor::saveUnmatchedNamedForwardReferences):
+        (JSC::Yarr::YarrPatternConstructor::atomNamedBackReference):
+        (JSC::Yarr::YarrPatternConstructor::isValidNamedForwardReference):
+        (JSC::Yarr::YarrPatternConstructor::atomNamedForwardReference):
+        (JSC::Yarr::YarrPattern::compile):
+        (JSC::Yarr::YarrPatternConstructor::reset): Deleted.
+        * yarr/YarrPattern.h:
+        (JSC::Yarr::YarrPattern::resetForReparsing):
+        (JSC::Yarr::YarrPattern::containsIllegalNamedForwardReferences):
+        (JSC::Yarr::YarrPattern::reset): Deleted.
+        * yarr/YarrSyntaxChecker.cpp:
+        (JSC::Yarr::SyntaxChecker::atomNamedBackReference):
+        (JSC::Yarr::SyntaxChecker::isValidNamedForwardReference):
+        (JSC::Yarr::SyntaxChecker::atomNamedForwardReference):
+
 2018-09-08  Yusuke Suzuki  <utatane....@gmail.com>
 
         [JSC] Remove loadModule function in jsc.cpp

Modified: trunk/Source/_javascript_Core/yarr/YarrParser.h (235881 => 235882)


--- trunk/Source/_javascript_Core/yarr/YarrParser.h	2018-09-11 03:59:41 UTC (rev 235881)
+++ trunk/Source/_javascript_Core/yarr/YarrParser.h	2018-09-11 04:53:56 UTC (rev 235882)
@@ -194,7 +194,9 @@
         // invoked with inCharacterClass set.
         NO_RETURN_DUE_TO_ASSERT void assertionWordBoundary(bool) { RELEASE_ASSERT_NOT_REACHED(); }
         NO_RETURN_DUE_TO_ASSERT void atomBackReference(unsigned) { RELEASE_ASSERT_NOT_REACHED(); }
-        NO_RETURN_DUE_TO_ASSERT void atomNamedBackReference(String) { RELEASE_ASSERT_NOT_REACHED(); }
+        NO_RETURN_DUE_TO_ASSERT void atomNamedBackReference(const String&) { RELEASE_ASSERT_NOT_REACHED(); }
+        NO_RETURN_DUE_TO_ASSERT bool isValidNamedForwardReference(const String&) { RELEASE_ASSERT_NOT_REACHED(); }
+        NO_RETURN_DUE_TO_ASSERT void atomNamedForwardReference(const String&) { RELEASE_ASSERT_NOT_REACHED(); }
 
     private:
         Delegate& m_delegate;
@@ -421,9 +423,16 @@
             if (!atEndOfPattern() && !inCharacterClass) {
                 if (consume() == '<') {
                     auto groupName = tryConsumeGroupName();
-                    if (groupName && m_captureGroupNames.contains(groupName.value())) {
-                        delegate.atomNamedBackReference(groupName.value());
-                        break;
+                    if (groupName) {
+                        if (m_captureGroupNames.contains(groupName.value())) {
+                            delegate.atomNamedBackReference(groupName.value());
+                            break;
+                        }
+                        
+                        if (delegate.isValidNamedForwardReference(groupName.value())) {
+                            delegate.atomNamedForwardReference(groupName.value());
+                            break;
+                        }
                     }
                     if (m_isUnicode) {
                         m_errorCode = ErrorCode::InvalidBackreference;
@@ -1136,7 +1145,9 @@
  *    void atomParentheticalAssertionBegin(bool invert = false);
  *    void atomParenthesesEnd();
  *    void atomBackReference(unsigned subpatternId);
- *    void atomNamedBackReference(String subpatternName);
+ *    void atomNamedBackReference(const String& subpatternName);
+ *    bool isValidNamedForwardReference(const String& subpatternName);
+ *    void atomNamedForwardReference(const String& subpatternName);
  *
  *    void quantifyAtom(unsigned min, unsigned max, bool greedy);
  *

Modified: trunk/Source/_javascript_Core/yarr/YarrPattern.cpp (235881 => 235882)


--- trunk/Source/_javascript_Core/yarr/YarrPattern.cpp	2018-09-11 03:59:41 UTC (rev 235881)
+++ trunk/Source/_javascript_Core/yarr/YarrPattern.cpp	2018-09-11 04:53:56 UTC (rev 235882)
@@ -446,9 +446,9 @@
     {
     }
 
-    void reset()
+    void resetForReparsing()
     {
-        m_pattern.reset();
+        m_pattern.resetForReparsing();
         m_characterClassConstructor.reset();
 
         auto body = std::make_unique<PatternDisjunction>();
@@ -456,7 +456,17 @@
         m_alternative = body->addNewAlternative();
         m_pattern.m_disjunctions.append(WTFMove(body));
     }
-    
+
+    void saveUnmatchedNamedForwardReferences()
+    {
+        m_unmatchedNamedForwardReferences.shrink(0);
+        
+        for (auto& entry : m_pattern.m_namedForwardReferences) {
+            if (!m_pattern.m_captureGroupNames.contains(entry))
+                m_unmatchedNamedForwardReferences.append(entry);
+        }
+    }
+
     void assertionBOL()
     {
         if (!m_alternative->m_terms.size() && !m_invertParentheticalAssertion) {
@@ -666,12 +676,23 @@
         m_alternative->m_terms.append(PatternTerm(subpatternId));
     }
 
-    void atomNamedBackReference(String subpatternName)
+    void atomNamedBackReference(const String& subpatternName)
     {
         ASSERT(m_pattern.m_namedGroupToParenIndex.find(subpatternName) != m_pattern.m_namedGroupToParenIndex.end());
         atomBackReference(m_pattern.m_namedGroupToParenIndex.get(subpatternName));
     }
 
+    bool isValidNamedForwardReference(const String& subpatternName)
+    {
+        return !m_unmatchedNamedForwardReferences.contains(subpatternName);
+    }
+
+    void atomNamedForwardReference(const String& subpatternName)
+    {
+        m_pattern.m_namedForwardReferences.appendIfNotContains(subpatternName);
+        m_alternative->m_terms.append(PatternTerm::ForwardReference());
+    }
+    
     // deep copy the argument disjunction.  If filterStartsWithBOL is true,
     // skip alternatives with m_startsWithBOL set true.
     PatternDisjunction* copyDisjunction(PatternDisjunction* disjunction, bool filterStartsWithBOL = false)
@@ -1080,6 +1101,7 @@
     YarrPattern& m_pattern;
     PatternAlternative* m_alternative;
     CharacterClassConstructor m_characterClassConstructor;
+    Vector<String> m_unmatchedNamedForwardReferences;
     void* m_stackLimit;
     bool m_invertCharacterClass;
     bool m_invertParentheticalAssertion { false };
@@ -1102,13 +1124,14 @@
     // Quoting Netscape's "What's new in _javascript_ 1.2",
     //      "Note: if the number of left parentheses is less than the number specified
     //       in \#, the \# is taken as an octal escape as described in the next row."
-    if (containsIllegalBackReference()) {
+    if (containsIllegalBackReference() || containsIllegalNamedForwardReferences()) {
         if (unicode())
             return ErrorCode::InvalidBackreference;
 
         unsigned numSubpatterns = m_numSubpatterns;
 
-        constructor.reset();
+        constructor.saveUnmatchedNamedForwardReferences();
+        constructor.resetForReparsing();
         ErrorCode error = parse(constructor, patternString, unicode(), numSubpatterns);
         ASSERT_UNUSED(error, !hasError(error));
         ASSERT(numSubpatterns == m_numSubpatterns);

Modified: trunk/Source/_javascript_Core/yarr/YarrPattern.h (235881 => 235882)


--- trunk/Source/_javascript_Core/yarr/YarrPattern.h	2018-09-11 03:59:41 UTC (rev 235881)
+++ trunk/Source/_javascript_Core/yarr/YarrPattern.h	2018-09-11 04:53:56 UTC (rev 235882)
@@ -354,7 +354,7 @@
 struct YarrPattern {
     JS_EXPORT_PRIVATE YarrPattern(const String& pattern, RegExpFlags, ErrorCode&, void* stackLimit = nullptr);
 
-    void reset()
+    void resetForReparsing()
     {
         m_numSubpatterns = 0;
         m_maxBackReference = 0;
@@ -381,6 +381,7 @@
         m_disjunctions.clear();
         m_userCharacterClasses.clear();
         m_captureGroupNames.shrink(0);
+        m_namedForwardReferences.shrink(0);
     }
 
     bool containsIllegalBackReference()
@@ -387,7 +388,20 @@
     {
         return m_maxBackReference > m_numSubpatterns;
     }
+    
+    bool containsIllegalNamedForwardReferences()
+    {
+        if (m_namedForwardReferences.isEmpty())
+            return false;
 
+        for (auto& entry : m_namedForwardReferences) {
+            if (!m_captureGroupNames.contains(entry))
+                return true;
+        }
+
+        return false;
+    }
+
     bool containsUnsignedLengthPattern()
     {
         return m_containsUnsignedLengthPattern;
@@ -513,6 +527,7 @@
     Vector<std::unique_ptr<PatternDisjunction>, 4> m_disjunctions;
     Vector<std::unique_ptr<CharacterClass>> m_userCharacterClasses;
     Vector<String> m_captureGroupNames;
+    Vector<String> m_namedForwardReferences;
     HashMap<String, unsigned> m_namedGroupToParenIndex;
 
 private:

Modified: trunk/Source/_javascript_Core/yarr/YarrSyntaxChecker.cpp (235881 => 235882)


--- trunk/Source/_javascript_Core/yarr/YarrSyntaxChecker.cpp	2018-09-11 03:59:41 UTC (rev 235881)
+++ trunk/Source/_javascript_Core/yarr/YarrSyntaxChecker.cpp	2018-09-11 04:53:56 UTC (rev 235882)
@@ -48,7 +48,9 @@
     void atomParentheticalAssertionBegin(bool = false) {}
     void atomParenthesesEnd() {}
     void atomBackReference(unsigned) {}
-    void atomNamedBackReference(String) {}
+    void atomNamedBackReference(const String&) {}
+    bool isValidNamedForwardReference(const String&) { return true; }
+    void atomNamedForwardReference(const String&) {}
     void quantifyAtom(unsigned, unsigned, bool) {}
     void disjunction() {}
 };

Modified: trunk/Source/WebCore/ChangeLog (235881 => 235882)


--- trunk/Source/WebCore/ChangeLog	2018-09-11 03:59:41 UTC (rev 235881)
+++ trunk/Source/WebCore/ChangeLog	2018-09-11 04:53:56 UTC (rev 235882)
@@ -1,3 +1,23 @@
+2018-09-10  Michael Saboff  <msab...@apple.com>
+
+        Test262 failure with Named Capture Groups - using a reference before the group is defined
+        https://bugs.webkit.org/show_bug.cgi?id=189407
+
+        Reviewed by Alex Christensen.
+
+        Created new delegate stubs for RegExp parsing.  These are not needed for the URL filtering
+        use cases.  Also changed all the delegate methods that take a String to take 
+        const String& to eliminate copy churn.
+
+        Updated TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp.
+
+        * contentextensions/URLFilterParser.cpp:
+        (WebCore::ContentExtensions::PatternParser::atomNamedBackReference):
+        (WebCore::ContentExtensions::PatternParser::isValidNamedForwardReference):
+        (WebCore::ContentExtensions::PatternParser::atomNamedForwardReference):
+        (WebCore::ContentExtensions::URLFilterParser::statusString):
+        * contentextensions/URLFilterParser.h:
+
 2018-09-10  Megan Gardner  <megan_gard...@apple.com>
 
         Correctly interpret from angle for conic gradients

Modified: trunk/Source/WebCore/contentextensions/URLFilterParser.cpp (235881 => 235882)


--- trunk/Source/WebCore/contentextensions/URLFilterParser.cpp	2018-09-11 03:59:41 UTC (rev 235881)
+++ trunk/Source/WebCore/contentextensions/URLFilterParser.cpp	2018-09-11 04:53:56 UTC (rev 235882)
@@ -129,11 +129,21 @@
         fail(URLFilterParser::BackReference);
     }
 
-    void atomNamedBackReference(String)
+    void atomNamedBackReference(const String&)
     {
         fail(URLFilterParser::BackReference);
     }
 
+    bool isValidNamedForwardReference(const String&)
+    {
+        return false;
+    }
+
+    void atomNamedForwardReference(const String&)
+    {
+        fail(URLFilterParser::ForwardReference);
+    }
+    
     void assertionBOL()
     {
         if (hasError())
@@ -372,6 +382,8 @@
         return "Character class is not supported.";
     case BackReference:
         return "Patterns cannot contain backreferences.";
+    case ForwardReference:
+        return "Patterns cannot contain forward references.";
     case MisplacedStartOfLine:
         return "Start of line assertion can only appear as the first term in a filter.";
     case WordBoundary:

Modified: trunk/Source/WebCore/contentextensions/URLFilterParser.h (235881 => 235882)


--- trunk/Source/WebCore/contentextensions/URLFilterParser.h	2018-09-11 03:59:41 UTC (rev 235881)
+++ trunk/Source/WebCore/contentextensions/URLFilterParser.h	2018-09-11 04:53:56 UTC (rev 235882)
@@ -43,6 +43,7 @@
         NonASCII,
         UnsupportedCharacterClass,
         BackReference,
+        ForwardReference,
         MisplacedStartOfLine,
         WordBoundary,
         AtomCharacter,

Modified: trunk/Tools/ChangeLog (235881 => 235882)


--- trunk/Tools/ChangeLog	2018-09-11 03:59:41 UTC (rev 235881)
+++ trunk/Tools/ChangeLog	2018-09-11 04:53:56 UTC (rev 235882)
@@ -1,3 +1,15 @@
+2018-09-10  Michael Saboff  <msab...@apple.com>
+
+        Test262 failure with Named Capture Groups - using a reference before the group is defined
+        https://bugs.webkit.org/show_bug.cgi?id=189407
+
+        Reviewed by Alex Christensen.
+
+        Updated test.
+
+        * TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
+        (TestWebKitAPI::TEST_F):
+
 2018-09-10  Thomas Denney  <tden...@apple.com>
 
         [WHLSL] Inlining should be optional

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp (235881 => 235882)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp	2018-09-11 03:59:41 UTC (rev 235881)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp	2018-09-11 04:53:56 UTC (rev 235882)
@@ -1773,7 +1773,13 @@
     testPatternStatus("a^", ContentExtensions::URLFilterParser::ParseStatus::MisplacedStartOfLine);
     testPatternStatus("(^)", ContentExtensions::URLFilterParser::ParseStatus::MisplacedStartOfLine);
     
-    testPatternStatus("(a)\\1", ContentExtensions::URLFilterParser::ParseStatus::Ok); // This should be BackReference, right?
+    testPatternStatus("(a)\\1", ContentExtensions::URLFilterParser::ParseStatus::Ok); // Back references are disabled, it parse as octal 1
+    testPatternStatus("(<A>a)\\k<A>", ContentExtensions::URLFilterParser::ParseStatus::Ok); // Named back references aren't handled, it parse as "k<A>"
+    testPatternStatus("\\1(a)", ContentExtensions::URLFilterParser::ParseStatus::Ok); // Forward references are disabled, it parse as octal 1
+    testPatternStatus("\\8(a)", ContentExtensions::URLFilterParser::ParseStatus::Ok); // Forward references are disabled, it parse as '8'
+    testPatternStatus("\\9(a)", ContentExtensions::URLFilterParser::ParseStatus::Ok); // Forward references are disabled, it parse as '9'
+    testPatternStatus("\\k<A>(<A>a)", ContentExtensions::URLFilterParser::ParseStatus::Ok); // Named forward references aren't handled, it parse as "k<A>"
+    testPatternStatus("\\k<A>(a)", ContentExtensions::URLFilterParser::ParseStatus::Ok); // Unmatched named forward references aren't handled, it parse as "k<A>"
 }
 
 TEST_F(ContentExtensionTest, PatternMatchingTheEmptyString)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to