mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:47:44 +00:00
LibRegex: Correctly translate BRE pattern end anchors
Previously we were always choosing the "nothing special" code path, even if the dollar symbol was at the end of the pattern (and therefore should have been considered special). Fix that by actually checking if the pattern end follows, and emitting the correct instruction if necessary.
This commit is contained in:
parent
fe1726521a
commit
ff38062318
1 changed files with 14 additions and 0 deletions
|
@ -516,6 +516,20 @@ bool PosixBasicParser::parse_one_char_or_collation_element(ByteCode& bytecode, s
|
|||
return true;
|
||||
}
|
||||
|
||||
// Dollars are special if at the end of a pattern.
|
||||
if (match(TokenType::Dollar)) {
|
||||
consume();
|
||||
|
||||
// If we are at the end of a pattern, emit an end check instruction.
|
||||
if (match(TokenType::Eof)) {
|
||||
bytecode.empend((ByteCodeValueType)OpCodeId::CheckEnd);
|
||||
return true;
|
||||
}
|
||||
|
||||
// We are not at the end of the string, so we should roll back and continue as normal.
|
||||
back(2);
|
||||
}
|
||||
|
||||
// None of these are special in BRE.
|
||||
if (match(TokenType::Char) || match(TokenType::Questionmark) || match(TokenType::RightParen) || match(TokenType::HyphenMinus)
|
||||
|| match(TokenType::Circumflex) || match(TokenType::RightCurly) || match(TokenType::Comma) || match(TokenType::Colon)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue