summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibRegex/RegexByteCode.cpp
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-08-29 11:05:12 -0400
committerTim Flynn <trflynn89@pm.me>2022-08-29 16:34:47 -0400
commit48cb15283a3e3a1378e6874dc5cf669edffaa17f (patch)
tree6468bdeea35c1ec4419e40d33b7bdc38a9abe05c /Userland/Libraries/LibRegex/RegexByteCode.cpp
parent27f5a18ce637598b83c5feec4e1392abe0100efc (diff)
downloadserenity-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 'Userland/Libraries/LibRegex/RegexByteCode.cpp')
-rw-r--r--Userland/Libraries/LibRegex/RegexByteCode.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/Userland/Libraries/LibRegex/RegexByteCode.cpp b/Userland/Libraries/LibRegex/RegexByteCode.cpp
index ace32620fc..e0c0ca4a27 100644
--- a/Userland/Libraries/LibRegex/RegexByteCode.cpp
+++ b/Userland/Libraries/LibRegex/RegexByteCode.cpp
@@ -557,11 +557,14 @@ ALWAYS_INLINE ExecutionResult OpCode_Compare::execute(MatchInput const& input, M
upper_case_needle = to_ascii_uppercase(needle);
lower_case_needle = to_ascii_lowercase(needle);
}
- if (lower_case_needle > range.to && upper_case_needle > range.to)
+
+ if (lower_case_needle >= range.from && lower_case_needle <= range.to)
+ return 0;
+ if (upper_case_needle >= range.from && upper_case_needle <= range.to)
+ return 0;
+ if (lower_case_needle > range.to || upper_case_needle > range.to)
return 1;
- if (lower_case_needle < range.from && upper_case_needle < range.from)
- return -1;
- return 0;
+ return -1;
});
if (matching_range) {