0

Fixes incorrect URL updates for registered schemes (e.g. "steam:")

Updating url.pathname of non-special scheme URLs whose schemes are
internally registered as opaque non-special schemes (e.g "steam:") adds
a leading slash wrongly.

This issue was found by a gurl_fuzzer.

The CL fixes their behaviors as follows:

Before:

> const url = new URL("steam:a")
> url.pathname = "b"
> url.href
"steam:/b"

After:

> const url = new URL("steam:a")
> url.pathname = "b"
> url.href
"steam:b"

Every other normal non-special scheme URL, like "git:a", doesn't have
this issue.

Bug: 40063064,375660989
Change-Id: I3a8104f48acf956747e0efa0cd7d612fe26a26e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5975076
Reviewed-by: Adam Rice <ricea@chromium.org>
Commit-Queue: Hayato Ito <hayato@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1376010}
This commit is contained in:
Hayato Ito
2024-10-31 01:08:40 +00:00
committed by Chromium LUCI CQ
parent 56ba632208
commit d79513ad76
2 changed files with 14 additions and 1 deletions

@ -829,6 +829,18 @@ TEST(GURLTest, Replacements) {
return url.ReplaceComponents(replacements);
},
.expected = "filesystem:http://www.google.com/foo/bar.html?foo#bar"},
// Regression test for https://crbug.com/375660989.
//
// "steam:" is explicitly registered as an opaque non-special scheme for
// compatibility reasons. See SchemeRegistry::opaque_non_special_schemes.
{.base = "steam:a",
.apply_replacements =
+[](const GURL& url) {
GURL::Replacements replacements;
replacements.SetPathStr("b");
return url.ReplaceComponents(replacements);
},
.expected = "steam:b"},
};
for (const ReplaceCase& c : replace_cases) {

@ -532,7 +532,8 @@ bool DoReplaceComponents(const char* spec,
return ReplaceMailtoURL(spec, parsed, replacements, output, out_parsed);
}
if (IsUsingStandardCompliantNonSpecialSchemeURLParsing()) {
if (IsUsingStandardCompliantNonSpecialSchemeURLParsing() &&
!DoIsOpaqueNonSpecial(spec, parsed.scheme)) {
return ReplaceNonSpecialURL(spec, parsed, replacements, charset_converter,
*output, *out_parsed);
}