LibURL/Pattern: Use opaque pathname serialization in canonicalization

The URL spec represents its path as a:

Variant<String, Vector<String>>

A URL is defined has having an opaque path if it has a single String,
the URL path otherwise containing a list of path components.

We (like in an older version of the spec) track this through a boolean
and only use a Vector with a single component for opaque paths.

This means it was incorrect to simple assign the path to a list with
a single empty string without setting that URL as opaque, which
meant that the path serialization was producing incorrect results.

It may make sense changing the API so this situation is a little more
clear. But for now, we simply need to set the opaque path boolean
to true here.
This commit is contained in:
Shannon Booth 2025-03-23 17:19:47 +13:00 committed by Tim Flynn
commit dcb7842f59
Notes: github-actions[bot] 2025-04-06 12:26:44 +00:00
2 changed files with 5 additions and 4 deletions

View file

@ -202,6 +202,7 @@ PatternErrorOr<String> canonicalize_an_opaque_pathname(String const& value)
// 3. Set dummyURLs path to the empty string.
dummy_url.set_paths({ "" });
dummy_url.set_has_an_opaque_path(true);
// 4. Let parseResult be the result of running URL parsing given value with dummyURL as url and opaque path state as state override.
auto parse_result = Parser::basic_parse(value, {}, &dummy_url, Parser::State::OpaquePath);

View file

@ -2,8 +2,8 @@ Harness status: OK
Found 350 tests
170 Pass
180 Fail
172 Pass
178 Fail
Pass Loading data...
Fail Pattern: [{"pathname":"/foo/bar"}] Inputs: [{"pathname":"/foo/bar"}]
Pass Pattern: [{"pathname":"/foo/bar"}] Inputs: [{"pathname":"/foo/ba"}]
@ -234,7 +234,7 @@ Pass Pattern: ["https://example.com/{bar}?foo"] Inputs: ["https://example.com/ba
Pass Pattern: ["https://example.com/{bar}\\?foo"] Inputs: ["https://example.com/bar?foo"]
Pass Pattern: ["https://example.com/"] Inputs: ["https://example.com:8080/"]
Pass Pattern: ["data:foobar"] Inputs: ["data:foobar"]
Fail Pattern: ["data\\:foobar"] Inputs: ["data:foobar"]
Pass Pattern: ["data\\:foobar"] Inputs: ["data:foobar"]
Pass Pattern: ["https://{sub.}?example.com/foo"] Inputs: ["https://example.com/foo"]
Fail Pattern: ["https://{sub.}?example{.com/}foo"] Inputs: ["https://example.com/foo"]
Pass Pattern: ["{https://}example.com/foo"] Inputs: ["https://example.com/foo"]
@ -260,7 +260,7 @@ Pass Pattern: ["https://foo@example.com"] Inputs: ["https://foo@example.com"]
Pass Pattern: ["https://\\:bar@example.com"] Inputs: ["https://:bar@example.com"]
Pass Pattern: ["https://:user::pass@example.com"] Inputs: ["https://foo:bar@example.com"]
Pass Pattern: ["https\\:foo\\:bar@example.com"] Inputs: ["https:foo:bar@example.com"]
Fail Pattern: ["data\\:foo\\:bar@example.com"] Inputs: ["data:foo:bar@example.com"]
Pass Pattern: ["data\\:foo\\:bar@example.com"] Inputs: ["data:foo:bar@example.com"]
Pass Pattern: ["https://foo{\\:}bar@example.com"] Inputs: ["https://foo:bar@example.com"]
Pass Pattern: ["data{\\:}channel.html","https://example.com"] Inputs: ["https://example.com/data:channel.html"]
Pass Pattern: ["http://[\\:\\:1]/"] Inputs: ["http://[::1]/"]