diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-07-10 22:02:18 +0430 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-07-10 22:58:24 +0430 |
commit | 1c584e9d801632f28b43da490656a8123b549f50 (patch) | |
tree | 9f396ec39091dbaa9fd4a246d5f4454b3373cfd5 /Userland | |
parent | 1c69c686e3261eff305669e9c2afe4fc5da5ba77 (diff) | |
download | serenity-1c584e9d801632f28b43da490656a8123b549f50.zip |
LibRegex: Correctly parse BRE bracket expressions
Commonly, bracket expressions are in fact, enclosed in brackets.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibRegex/RegexParser.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/Userland/Libraries/LibRegex/RegexParser.cpp b/Userland/Libraries/LibRegex/RegexParser.cpp index d794721d94..814759de4e 100644 --- a/Userland/Libraries/LibRegex/RegexParser.cpp +++ b/Userland/Libraries/LibRegex/RegexParser.cpp @@ -481,12 +481,20 @@ bool PosixBasicParser::parse_one_char_or_collation_element(ByteCode& bytecode, s Vector<CompareTypeAndValuePair> values; size_t bracket_minimum_length = 0; - if (!AbstractPosixParser::parse_bracket_expression(values, bracket_minimum_length)) - return false; - bytecode.insert_bytecode_compare_values(move(values)); - match_length_minimum += bracket_minimum_length; - return !has_error(); + if (match(TokenType::LeftBracket)) { + consume(); + if (!AbstractPosixParser::parse_bracket_expression(values, bracket_minimum_length)) + return false; + + consume(TokenType::RightBracket, Error::MismatchingBracket); + + bytecode.insert_bytecode_compare_values(move(values)); + match_length_minimum += bracket_minimum_length; + return !has_error(); + } + + return set_error(Error::InvalidPattern); } // ============================= |