From 0a58497ab99e469561937e1feb17db6835a8796f Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Mon, 7 Apr 2025 15:50:06 +1200 Subject: [PATCH] LibURL/Pattern: Fix PatternParser logic for prefix codepoint comparison We were not properly handling the case that prefix code point was the empty string (which we represent as an OptionalNone). While this still resulted in the correct pattern string being generated, an incorrect regular expression was being generated causing matching to fail. --- Libraries/LibURL/Pattern/PatternParser.cpp | 2 +- .../Text/expected/wpt-import/urlpattern/urlpattern.any.txt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Libraries/LibURL/Pattern/PatternParser.cpp b/Libraries/LibURL/Pattern/PatternParser.cpp index 53e9539f638..844f46f2187 100644 --- a/Libraries/LibURL/Pattern/PatternParser.cpp +++ b/Libraries/LibURL/Pattern/PatternParser.cpp @@ -311,7 +311,7 @@ PatternErrorOr> PatternParser::parse(Utf8View const& input, Options prefix = char_token->value; // 3. If prefix is not the empty string and not options’s prefix code point: - if (!prefix.is_empty() && options.prefix_code_point.has_value() && prefix != String::from_code_point(*options.prefix_code_point)) { + if (!prefix.is_empty() && (!options.prefix_code_point.has_value() || prefix != String::from_code_point(*options.prefix_code_point))) { // 1. Append prefix to the end of parser’s pending fixed value. parser.m_pending_fixed_value.append(prefix); diff --git a/Tests/LibWeb/Text/expected/wpt-import/urlpattern/urlpattern.any.txt b/Tests/LibWeb/Text/expected/wpt-import/urlpattern/urlpattern.any.txt index 1b2d5cabebe..40426470caa 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/urlpattern/urlpattern.any.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/urlpattern/urlpattern.any.txt @@ -2,8 +2,8 @@ Harness status: OK Found 354 tests -352 Pass -2 Fail +353 Pass +1 Fail Pass Loading data... Pass Pattern: [{"pathname":"/foo/bar"}] Inputs: [{"pathname":"/foo/bar"}] Pass Pattern: [{"pathname":"/foo/bar"}] Inputs: [{"pathname":"/foo/ba"}] @@ -282,7 +282,7 @@ Pass Pattern: [{"hostname":"[*\\:1]"}] Inputs: [{"hostname":"[::ab:1]"}] Pass Pattern: [{"hostname":"*\\:1]"}] Inputs: undefined Pass Pattern: ["https://foo{{@}}example.com"] Inputs: ["https://foo@example.com"] Pass Pattern: ["https://foo{@example.com"] Inputs: ["https://foo@example.com"] -Fail Pattern: ["data\\:text/javascript,let x = 100/:tens?5;"] Inputs: ["data:text/javascript,let x = 100/5;"] +Pass Pattern: ["data\\:text/javascript,let x = 100/:tens?5;"] Inputs: ["data:text/javascript,let x = 100/5;"] Pass Pattern: [{"pathname":"/:id/:id"}] Inputs: undefined Pass Pattern: [{"pathname":"/foo","baseURL":""}] Inputs: undefined Pass Pattern: ["/foo",""] Inputs: undefined