-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net/url: improve url parsing error messages by quoting
Current implementation doesn't always make it obvious what the exact problem with the URL is, so this makes it clearer by consistently quoting the invalid URL, as is the norm in other parsing implementations, eg.: strconv.Atoi(" 123") returns an error: parsing " 123": invalid syntax Updates #29261 Change-Id: Icc6bff8b4a4584677c0f769992823e6e1e0d397d GitHub-Last-Rev: 648b9d93fe149ec90f3aeca73019158a344de03e GitHub-Pull-Request: golang/go#29384 Reviewed-on: https://go-review.googlesource.com/c/go/+/185117 Reviewed-by: Daniel Martí <[email protected]> Run-TryBot: Daniel Martí <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
- Loading branch information
Showing
4 changed files
with
17 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -221,27 +221,27 @@ func TestClientRedirects(t *testing.T) { | |
|
||
c := ts.Client() | ||
_, err := c.Get(ts.URL) | ||
if e, g := "Get /?n=10: stopped after 10 redirects", fmt.Sprintf("%v", err); e != g { | ||
if e, g := `Get "/?n=10": stopped after 10 redirects`, fmt.Sprintf("%v", err); e != g { | ||
t.Errorf("with default client Get, expected error %q, got %q", e, g) | ||
} | ||
|
||
// HEAD request should also have the ability to follow redirects. | ||
_, err = c.Head(ts.URL) | ||
if e, g := "Head /?n=10: stopped after 10 redirects", fmt.Sprintf("%v", err); e != g { | ||
if e, g := `Head "/?n=10": stopped after 10 redirects`, fmt.Sprintf("%v", err); e != g { | ||
t.Errorf("with default client Head, expected error %q, got %q", e, g) | ||
} | ||
|
||
// Do should also follow redirects. | ||
greq, _ := NewRequest("GET", ts.URL, nil) | ||
_, err = c.Do(greq) | ||
if e, g := "Get /?n=10: stopped after 10 redirects", fmt.Sprintf("%v", err); e != g { | ||
if e, g := `Get "/?n=10": stopped after 10 redirects`, fmt.Sprintf("%v", err); e != g { | ||
t.Errorf("with default client Do, expected error %q, got %q", e, g) | ||
} | ||
|
||
// Requests with an empty Method should also redirect (Issue 12705) | ||
greq.Method = "" | ||
_, err = c.Do(greq) | ||
if e, g := "Get /?n=10: stopped after 10 redirects", fmt.Sprintf("%v", err); e != g { | ||
if e, g := `Get "/?n=10": stopped after 10 redirects`, fmt.Sprintf("%v", err); e != g { | ||
t.Errorf("with default client Do and empty Method, expected error %q, got %q", e, g) | ||
} | ||
|
||
|
@@ -1172,22 +1172,22 @@ func TestStripPasswordFromError(t *testing.T) { | |
{ | ||
desc: "Strip password from error message", | ||
in: "https://user:[email protected]/", | ||
out: "Get https://user:***@dummy.faketld/: dummy impl", | ||
out: `Get "https://user:***@dummy.faketld/": dummy impl`, | ||
}, | ||
{ | ||
desc: "Don't Strip password from domain name", | ||
in: "https://user:[email protected]/", | ||
out: "Get https://user:***@password.faketld/: dummy impl", | ||
out: `Get "https://user:***@password.faketld/": dummy impl`, | ||
}, | ||
{ | ||
desc: "Don't Strip password from path", | ||
in: "https://user:[email protected]/password", | ||
out: "Get https://user:***@dummy.faketld/password: dummy impl", | ||
out: `Get "https://user:***@dummy.faketld/password": dummy impl`, | ||
}, | ||
{ | ||
desc: "Strip escaped password", | ||
in: "https://user:pa%[email protected]/", | ||
out: "Get https://user:***@dummy.faketld/: dummy impl", | ||
out: `Get "https://user:***@dummy.faketld/": dummy impl`, | ||
}, | ||
} | ||
for _, tC := range testCases { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters