mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-06 16:09:30 +00:00
LibRegex: Consider the inverse=true case when finding pattern overlap
Previously we were only checking for overlap when the range wasn't in inverse mode, which made us miss things like /[^x]x/; this patch makes it so we don't miss that.
This commit is contained in:
parent
936a9fd759
commit
af441bb939
|
@ -984,6 +984,8 @@ TEST_CASE(optimizer_atomic_groups)
|
|||
Tuple { "(1+)0"sv, "10"sv, true },
|
||||
// Rewrite should not skip over first required iteration of <x>+.
|
||||
Tuple { "a+"sv, ""sv, false },
|
||||
// 'y' and [^x] have an overlap ('y'), the loop should not be rewritten here.
|
||||
Tuple { "[^x]+y"sv, "ay"sv, true },
|
||||
};
|
||||
|
||||
for (auto& test : tests) {
|
||||
|
|
|
@ -251,7 +251,7 @@ static bool has_overlap(Vector<CompareTypeAndValuePair> const& lhs, Vector<Compa
|
|||
return true;
|
||||
break;
|
||||
case CharacterCompareType::Char:
|
||||
if (!current_lhs_inversion_state() && range_contains(pair.value))
|
||||
if (current_lhs_inversion_state() ^ range_contains(pair.value))
|
||||
return true;
|
||||
break;
|
||||
case CharacterCompareType::String:
|
||||
|
@ -259,12 +259,12 @@ static bool has_overlap(Vector<CompareTypeAndValuePair> const& lhs, Vector<Compa
|
|||
// Just bail out to avoid false positives.
|
||||
return true;
|
||||
case CharacterCompareType::CharClass:
|
||||
if (!current_lhs_inversion_state() && char_class_contains(static_cast<CharClass>(pair.value)))
|
||||
if (current_lhs_inversion_state() ^ char_class_contains(static_cast<CharClass>(pair.value)))
|
||||
return true;
|
||||
break;
|
||||
case CharacterCompareType::CharRange: {
|
||||
auto range = CharRange(pair.value);
|
||||
if (!current_lhs_inversion_state() && range_contains(range))
|
||||
if (current_lhs_inversion_state() ^ range_contains(range))
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue