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:

committed by
Chromium LUCI CQ

parent
237a4db63d
commit
61f871feed
@ -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);
|
||||
|
Reference in New Issue
Block a user