diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2021-04-12 10:58:59 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-04-12 08:54:58 +0200 |
commit | 5a14f7ea2f510bb3492d5f450934333bd736f582 (patch) | |
tree | 4bd047e225a21672ddb113ce3a3372557201aee1 | |
parent | 7c98a6be17e7d17f4e0d1b81ff92fa3242d2ff0c (diff) | |
download | serenity-5a14f7ea2f510bb3492d5f450934333bd736f582.zip |
LibRegex: Generate a 'Compare' op for empty character classes
Otherwise it would match zero-length strings.
Fixes #6256.
-rw-r--r-- | Userland/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.exec.js | 12 | ||||
-rw-r--r-- | Userland/Libraries/LibRegex/RegexParser.cpp | 3 |
2 files changed, 15 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.exec.js b/Userland/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.exec.js index f781a5bb3f..e818556337 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.exec.js +++ b/Userland/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.exec.js @@ -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"); +}); diff --git a/Userland/Libraries/LibRegex/RegexParser.cpp b/Userland/Libraries/LibRegex/RegexParser.cpp index 0fa6305916..7212eaf792 100644 --- a/Userland/Libraries/LibRegex/RegexParser.cpp +++ b/Userland/Libraries/LibRegex/RegexParser.cpp @@ -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; } |