]> Cypherpunks repositories - gostls13.git/commitdiff
net/url: consider ForceQuery in ResolveReference
authorTimothy Gu <timothygu99@gmail.com>
Fri, 7 May 2021 08:03:59 +0000 (01:03 -0700)
committerDamien Neil <dneil@google.com>
Tue, 2 Nov 2021 00:12:17 +0000 (00:12 +0000)
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>

src/net/url/url.go
src/net/url/url_test.go

index d571ab2fc4df0d7b266ccf519954574ba4f47383..f31aa08b5929db2880fd22ec735e2db3692cc222 100644 (file)
@@ -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
index 6807d58f1af6c98fb212ec4d4a7a7040cd6c4c47..7c807d7a38528853e7e2d59eaaa6771921199bf1 100644 (file)
@@ -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) {