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);