summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTimothy Gu <timothygu99@gmail.com>2021-05-07 01:03:59 -0700
committerDamien Neil <dneil@google.com>2021-11-02 00:12:17 +0000
commit81fea0b4fd3b134d4c1d121abad171e358037ce3 (patch)
treef0d9927d48c7bbe79af5f26fd13bfef67670d6cb /src
parent02e5913406b2ac354695471690b79d8d4242ad8d (diff)
downloadgo-git-81fea0b4fd3b134d4c1d121abad171e358037ce3.tar.gz
net/url: consider ForceQuery in ResolveReference
Previously, when resolving references of form (https://golang.org/?hello).ResolveReference(?) we only used URL.RawQuery to determine whether or not a query part is defined. Go 1.7 introduced URL.ForceQuery as a flag for the situation where a query part is provided but empty. But we did not use it in ResolveReference. This leads to the erroneous output https://golang.org/?hello when the correct output should be https://golang.org/? This commit rectifies that error. Fixes #46033 Change-Id: I05bc0b48bf2bbf13b4ddc0dd10599ea613dc2188 Reviewed-on: https://go-review.googlesource.com/c/go/+/317930 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Damien Neil <dneil@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/net/url/url.go2
-rw-r--r--src/net/url/url_test.go3
2 files changed, 4 insertions, 1 deletions
diff --git a/src/net/url/url.go b/src/net/url/url.go
index d571ab2fc4..f31aa08b59 100644
--- a/src/net/url/url.go
+++ b/src/net/url/url.go
@@ -1083,7 +1083,7 @@ func (u *URL) ResolveReference(ref *URL) *URL {
url.Path = ""
return &url
}
- if ref.Path == "" && ref.RawQuery == "" {
+ if ref.Path == "" && !ref.ForceQuery && ref.RawQuery == "" {
url.RawQuery = u.RawQuery
if ref.Fragment == "" {
url.Fragment = u.Fragment
diff --git a/src/net/url/url_test.go b/src/net/url/url_test.go
index 6807d58f1a..7c807d7a38 100644
--- a/src/net/url/url_test.go
+++ b/src/net/url/url_test.go
@@ -1244,6 +1244,9 @@ var resolveReferenceTests = []struct {
{"https://a/b/c/d;p?q", "//g/d/e/f?y#s", "https://g/d/e/f?y#s"},
{"https://a/b/c/d;p#s", "?y", "https://a/b/c/d;p?y"},
{"https://a/b/c/d;p?q#s", "?y", "https://a/b/c/d;p?y"},
+
+ // Empty path and query but with ForceQuery (issue 46033).
+ {"https://a/b/c/d;p?q#s", "?", "https://a/b/c/d;p?"},
}
func TestResolveReference(t *testing.T) {