Browse Source

LibRegex: Allow quantifiers after quantifiable assertions

While quantifying assertions is very much meaningless, the specification
allows them with annex B's extended grammar for browsers, so read and
apply the quantifiers.
Fixes #12373.
Ali Mohammad Pur 3 years ago
parent
commit
627bbee055
2 changed files with 4 additions and 0 deletions
  1. 1 0
      Tests/LibRegex/Regex.cpp
  2. 3 0
      Userland/Libraries/LibRegex/RegexParser.cpp

+ 1 - 0
Tests/LibRegex/Regex.cpp

@@ -599,6 +599,7 @@ TEST_CASE(ECMA262_parse)
         { "(?<$$_$$>a)"sv },
         { "(?<ÿ>a)"sv },
         { "(?<𝓑𝓻𝓸𝔀𝓷>a)"sv },
+        { "((?=lg)?[vl]k\\-?\\d{3}) bui| 3\\.[-\\w; ]{10}lg?-([06cv9]{3,4})"sv, regex::Error::NoError, ECMAScriptFlags::BrowserExtended } // #12373, quantifiable assertions.
     };
 
     for (auto& test : tests) {

+ 3 - 0
Userland/Libraries/LibRegex/RegexParser.cpp

@@ -1083,6 +1083,9 @@ bool ECMA262Parser::parse_assertion(ByteCode& stack, [[maybe_unused]] size_t& ma
         if (m_should_use_browser_extended_grammar) {
             if (!unicode) {
                 if (parse_quantifiable_assertion(assertion_stack, match_length_minimum, named)) {
+                    if (!parse_quantifier(assertion_stack, match_length_minimum, unicode, named))
+                        return false;
+
                     stack.extend(move(assertion_stack));
                     return true;
                 }