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.
This commit is contained in:
Shannon Booth 2025-04-07 15:50:06 +12:00
parent b1b8f6107a
commit 5fef3b861f
2 changed files with 4 additions and 4 deletions

View file

@ -311,7 +311,7 @@ PatternErrorOr<Vector<Part>> PatternParser::parse(Utf8View const& input, Options
prefix = char_token->value;
// 3. If prefix is not the empty string and not optionss 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 parsers pending fixed value.
parser.m_pending_fixed_value.append(prefix);

View file

@ -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