From 8b2644a63082974375c649a851e9d1d14148485e Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Mon, 7 Apr 2025 11:24:01 +1200 Subject: [PATCH] LibURL/Pattern: Do not trim whitespace interpreting port It turns out that the problem here was simply that we were trimming trailing whitespace when we did not need to, which was meaning that the port number of '80 ' was being converted to the empty string per URLPattern elision as the port matches the http scheme. --- Libraries/LibURL/Pattern/Pattern.cpp | 2 +- .../Text/expected/wpt-import/urlpattern/urlpattern.any.txt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Libraries/LibURL/Pattern/Pattern.cpp b/Libraries/LibURL/Pattern/Pattern.cpp index 7a4da8edeb1..bfcefdda33f 100644 --- a/Libraries/LibURL/Pattern/Pattern.cpp +++ b/Libraries/LibURL/Pattern/Pattern.cpp @@ -95,7 +95,7 @@ PatternErrorOr Pattern::create(Input const& input, Optional con // 6. If processedInit["protocol"] is a special scheme and processedInit["port"] is a string which represents its // corresponding default port in radix-10 using ASCII digits then set processedInit["port"] to the empty string. if (is_special_scheme(processed_init.protocol.value())) { - auto maybe_port = processed_init.port->to_number(); + auto maybe_port = processed_init.port->to_number(TrimWhitespace::No); if (maybe_port.has_value() && *maybe_port == default_port_for_scheme(*processed_init.protocol).value()) processed_init.port = String {}; } 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 06c928f6346..1b2d5cabebe 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 -351 Pass -3 Fail +352 Pass +2 Fail Pass Loading data... Pass Pattern: [{"pathname":"/foo/bar"}] Inputs: [{"pathname":"/foo/bar"}] Pass Pattern: [{"pathname":"/foo/bar"}] Inputs: [{"pathname":"/foo/ba"}] @@ -170,7 +170,7 @@ Pass Pattern: [{"pathname":": Pass Pattern: [{"port":""}] Inputs: [{"protocol":"http","port":"80"}] Pass Pattern: [{"protocol":"http","port":"80"}] Inputs: [{"protocol":"http","port":"80"}] Pass Pattern: [{"protocol":"http","port":"80{20}?"}] Inputs: [{"protocol":"http","port":"80"}] -Fail Pattern: [{"protocol":"http","port":"80 "}] Inputs: [{"protocol":"http","port":"80"}] +Pass Pattern: [{"protocol":"http","port":"80 "}] Inputs: [{"protocol":"http","port":"80"}] Pass Pattern: [{"protocol":"http","port":"100000"}] Inputs: [{"protocol":"http","port":"100000"}] Pass Pattern: [{"port":"80"}] Inputs: [{"protocol":"http","port":"80"}] Pass Pattern: [{"protocol":"http{s}?","port":"80"}] Inputs: [{"protocol":"http","port":"80"}]