mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Allow trailing '*'s in a glob pattern to match nothing
Fixes part of #4607.
This commit is contained in:
parent
2ad5bfd78e
commit
cbe0a8b403
Notes:
sideshowbarker
2024-07-19 00:28:01 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/cbe0a8b4032 Pull-request: https://github.com/SerenityOS/serenity/pull/4608
2 changed files with 16 additions and 0 deletions
|
@ -93,6 +93,14 @@ bool matches(const StringView& str, const StringView& mask, CaseSensitivity case
|
|||
++mask_ptr;
|
||||
}
|
||||
|
||||
if (string_ptr == string_end) {
|
||||
// Allow ending '*' to contain nothing.
|
||||
while (mask_ptr != mask_end && *mask_ptr == '*') {
|
||||
record_span(string_ptr - string_start, 0);
|
||||
++mask_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
return string_ptr == string_end && mask_ptr == mask_end;
|
||||
}
|
||||
|
||||
|
|
|
@ -86,6 +86,14 @@ TEST_CASE(matches_with_positions)
|
|||
EXPECT_EQ(spans, Vector<AK::MaskSpan>({ { 1, 3 } }));
|
||||
}
|
||||
|
||||
// #4607
|
||||
TEST_CASE(matches_trailing)
|
||||
{
|
||||
EXPECT(AK::StringUtils::matches("ab", "ab*"));
|
||||
EXPECT(AK::StringUtils::matches("ab", "ab****"));
|
||||
EXPECT(AK::StringUtils::matches("ab", "*ab****"));
|
||||
}
|
||||
|
||||
TEST_CASE(convert_to_int)
|
||||
{
|
||||
auto value = AK::StringUtils::convert_to_int(StringView());
|
||||
|
|
Loading…
Reference in a new issue