summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibRegex/RegexByteCode.cpp
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2022-07-07 23:27:51 +0430
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2022-07-09 01:00:44 +0000
commitb85666b3d203bb39e75da8d582e428800f4cb26c (patch)
treee82cf410f23232828c2f0200832ed7dfccfd80f1 /Userland/Libraries/LibRegex/RegexByteCode.cpp
parentb7c50f7094577c61de9fdc35466b37f0f1927551 (diff)
downloadserenity-b85666b3d203bb39e75da8d582e428800f4cb26c.zip
LibRegex: Fix lookup table-based range checks in Compare
The lowercase version of a range is not required to be a valid range, instead of casefolding the range and making it invalid, check twice with both cases of the input character (which are the same as the input if not insensitive). This time includes an actual test :^)
Diffstat (limited to 'Userland/Libraries/LibRegex/RegexByteCode.cpp')
-rw-r--r--Userland/Libraries/LibRegex/RegexByteCode.cpp13
1 files changed, 6 insertions, 7 deletions
diff --git a/Userland/Libraries/LibRegex/RegexByteCode.cpp b/Userland/Libraries/LibRegex/RegexByteCode.cpp
index de7ce26444..cccdb93982 100644
--- a/Userland/Libraries/LibRegex/RegexByteCode.cpp
+++ b/Userland/Libraries/LibRegex/RegexByteCode.cpp
@@ -531,16 +531,15 @@ ALWAYS_INLINE ExecutionResult OpCode_Compare::execute(MatchInput const& input, M
auto ch = input.view.substring_view(state.string_position, 1)[0];
auto const* matching_range = binary_search(range_data, ch, nullptr, [insensitive = input.regex_options & AllFlags::Insensitive](auto needle, CharRange range) {
- auto from = range.from;
- auto to = range.to;
+ auto upper_case_needle = needle;
+ auto lower_case_needle = needle;
if (insensitive) {
- from = to_ascii_lowercase(from);
- to = to_ascii_lowercase(to);
- needle = to_ascii_lowercase(needle);
+ upper_case_needle = to_ascii_uppercase(needle);
+ lower_case_needle = to_ascii_lowercase(needle);
}
- if (needle > to)
+ if (lower_case_needle > range.to && upper_case_needle > range.to)
return 1;
- if (needle < from)
+ if (lower_case_needle < range.from && upper_case_needle < range.from)
return -1;
return 0;
});