mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-24 02:03:06 -05:00
LibRegex: Generate a 'Compare' op for empty character classes
Otherwise it would match zero-length strings. Fixes #6256.
This commit is contained in:
parent
7c98a6be17
commit
5a14f7ea2f
Notes:
sideshowbarker
2024-07-18 20:30:21 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/5a14f7ea2f5 Pull-request: https://github.com/SerenityOS/serenity/pull/6260 Issue: https://github.com/SerenityOS/serenity/issues/6256
2 changed files with 15 additions and 0 deletions
|
@ -136,3 +136,15 @@ test("brace quantifier with invalid contents", () => {
|
|||
expect(res.length).toBe(1);
|
||||
expect(res[0]).toBe("{{lit-746579221856449}}");
|
||||
});
|
||||
|
||||
// #6256
|
||||
test("empty character class semantics", () => {
|
||||
// Should not match zero-length strings.
|
||||
let res = /[]/.exec("");
|
||||
expect(res).toBe(null);
|
||||
|
||||
// Inverse form, should match anything.
|
||||
res = /[^]/.exec("x");
|
||||
expect(res.length).toBe(1);
|
||||
expect(res[0]).toBe("x");
|
||||
});
|
||||
|
|
|
@ -1418,6 +1418,9 @@ bool ECMA262Parser::parse_character_class(ByteCode& stack, size_t& match_length_
|
|||
|
||||
if (match(TokenType::RightBracket)) {
|
||||
consume();
|
||||
// Should only have at most an 'Inverse'
|
||||
VERIFY(compares.size() <= 1);
|
||||
stack.insert_bytecode_compare_values(move(compares));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue