diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-07-24 13:00:14 +0430 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-07-24 20:52:43 +0430 |
commit | faef523567b228dc9ebf683555eb4cbee19c7bb6 (patch) | |
tree | 6b55819120aeb0038e41fc7b4f1d3ffc00c34001 /Userland | |
parent | 1dd137815970555c34c49bdb3c2049819a178c7d (diff) | |
download | serenity-faef523567b228dc9ebf683555eb4cbee19c7bb6.zip |
LibRegex: Make unclosed-at-eof brace quantifiers an error
Otherwise we'd just loop trying to parse it over and over again, for
instance in `/a{/` or `/a{1,/`.
Unless we're parsing in Annex B mode, which allows `{` as a normal
ExtendedSourceCharacter.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibRegex/RegexParser.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/Userland/Libraries/LibRegex/RegexParser.cpp b/Userland/Libraries/LibRegex/RegexParser.cpp index becff1810f..afa4d52b21 100644 --- a/Userland/Libraries/LibRegex/RegexParser.cpp +++ b/Userland/Libraries/LibRegex/RegexParser.cpp @@ -1153,7 +1153,10 @@ bool ECMA262Parser::parse_quantifier(ByteCode& stack, size_t& match_length_minim auto low_bound = low_bound_string.to_uint(); if (!low_bound.has_value()) { - back(chars_consumed + 1); + if (!m_should_use_browser_extended_grammar && done()) + return set_error(Error::MismatchingBrace); + + back(chars_consumed + !done()); return true; } @@ -1173,7 +1176,10 @@ bool ECMA262Parser::parse_quantifier(ByteCode& stack, size_t& match_length_minim } if (!match(TokenType::RightCurly)) { - back(chars_consumed + 1); + if (!m_should_use_browser_extended_grammar && done()) + return set_error(Error::MismatchingBrace); + + back(chars_consumed + !done()); return true; } @@ -1297,7 +1303,7 @@ bool ECMA262Parser::parse_invalid_braced_quantifier() StringView high_bound; if (low_bound.is_empty()) { - back(chars_consumed + 1); + back(chars_consumed + !done()); return false; } chars_consumed += low_bound.length(); @@ -1310,7 +1316,7 @@ bool ECMA262Parser::parse_invalid_braced_quantifier() } if (!match(TokenType::RightCurly)) { - back(chars_consumed + 1); + back(chars_consumed + !done()); return false; } |