0

URL: Carry over has_opaque_path flag in ReplaceNonSpecialURL

Fix a regression reported in https://crbug.com/362674372.

ReplaceNonSpecialURL currently forgets to carry over the
has_opaque_path flag. Note that CanonicalizeNonSpecialURL already
does.

This leads to an issue where calling url.searchParam.set() twice for
non-special opaque path URLs triggers to call
DoCanonicalizeNonSpecialURL incorrectly instead of ReplacePathURL.
This, in turn, causes the reported bug of a prepended "/" (slash) in
the path.

Bug: 362674372, 40063064
Change-Id: Iabaf568f95b709fb6b1731f648dbaeebc7abf661
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5823812
Reviewed-by: Adam Rice <ricea@chromium.org>
Commit-Queue: Hayato Ito <hayato@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1348535}
This commit is contained in:
Hayato Ito
2024-08-29 10:25:45 +00:00
committed by Chromium LUCI CQ
parent 237a4db63d
commit 61f871feed
2 changed files with 16 additions and 0 deletions
third_party/blink/renderer/platform/weborigin
url

@ -1128,6 +1128,16 @@ TEST(KURLTest, IPv4EmbeddedIPv6Address) {
EXPECT_FALSE(KURL(u"http://[::1.2.]/").IsValid());
}
// Regression test for https://crbug.com/362674372.
TEST(KURLTest, SetQueryTwice) {
KURL url("data:example");
EXPECT_EQ(url.GetString(), "data:example");
url.SetQuery("q=1");
EXPECT_EQ(url.GetString(), "data:example?q=1");
url.SetQuery("q=2");
EXPECT_EQ(url.GetString(), "data:example?q=2");
}
enum class PortIsValid {
// The constructor does strict checking. Ports which are considered valid by
// the constructor are kAlways valid.

@ -217,6 +217,9 @@ bool ReplaceNonSpecialURL(const char* base,
CharsetConverter* query_converter,
CanonOutput& output,
Parsed& new_parsed) {
// Carry over the flag.
new_parsed.has_opaque_path = base_parsed.has_opaque_path;
if (base_parsed.has_opaque_path) {
return ReplacePathURL(base, base_parsed, replacements, &output,
&new_parsed);
@ -237,6 +240,9 @@ bool ReplaceNonSpecialURL(const char* base,
CharsetConverter* query_converter,
CanonOutput& output,
Parsed& new_parsed) {
// Carry over the flag.
new_parsed.has_opaque_path = base_parsed.has_opaque_path;
if (base_parsed.has_opaque_path) {
return ReplacePathURL(base, base_parsed, replacements, &output,
&new_parsed);