diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-08-29 11:05:12 -0400 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2022-08-29 16:34:47 -0400 |
commit | 48cb15283a3e3a1378e6874dc5cf669edffaa17f (patch) | |
tree | 6468bdeea35c1ec4419e40d33b7bdc38a9abe05c /Tests/LibRegex/Regex.cpp | |
parent | 27f5a18ce637598b83c5feec4e1392abe0100efc (diff) | |
download | serenity-48cb15283a3e3a1378e6874dc5cf669edffaa17f.zip |
LibRegex: Explicitly check if a character falls into a table-based range
Previously, for a regex such as /[a-sy-z]/i, we would incorrectly think
the character "u" fell into the range "a-s" because neither of the
conditions "u > s && U > s" or "u < a && U < a" would be true, resulting
in the lookup falling back to assuming the character is in the range.
Instead, first explicitly check if the character falls into the range,
rather than checking if it falls outside the range. If the explicit
checks fail, then we know the character is outside the range.
Diffstat (limited to 'Tests/LibRegex/Regex.cpp')
-rw-r--r-- | Tests/LibRegex/Regex.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Tests/LibRegex/Regex.cpp b/Tests/LibRegex/Regex.cpp index daeb623c43..2b4da92c98 100644 --- a/Tests/LibRegex/Regex.cpp +++ b/Tests/LibRegex/Regex.cpp @@ -690,7 +690,10 @@ TEST_CASE(ECMA262_match) { "a|$"sv, "x"sv, true, (ECMAScriptFlags)regex::AllFlags::Global }, // #11940, Global (not the 'g' flag) regexps should attempt to match the zero-length end of the string too. { "foo\nbar"sv, "foo\nbar"sv, true }, // #12126, ECMA262 regexp should match literal newlines without the 's' flag. { "foo[^]bar"sv, "foo\nbar"sv, true }, // #12126, ECMA262 regexp should match newline with [^]. - { "^[_A-Z]+$"sv, "_aA"sv, true, ECMAScriptFlags::Insensitive } // Insensitive lookup table: characters in a range do not necessarily lie in the same range after being converted to lowercase. + { "^[_A-Z]+$"sv, "_aA"sv, true, ECMAScriptFlags::Insensitive }, // Insensitive lookup table: characters in a range do not necessarily lie in the same range after being converted to lowercase. + { "^[a-sy-z]$"sv, "b"sv, true, ECMAScriptFlags::Insensitive }, + { "^[a-sy-z]$"sv, "y"sv, true, ECMAScriptFlags::Insensitive }, + { "^[a-sy-z]$"sv, "u"sv, false, ECMAScriptFlags::Insensitive }, }; // clang-format on |