mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
net/url: prefix relative paths containing ":" in the first segment with "./"
This change modifies URL.String to prepend "./" to a relative URL which contains a colon in the first path segment. Per RFC 3986 §4.2: > A path segment that contains a colon character (e.g., "this:that") > cannot be used as the first segment of a relative-path reference, as > it would be mistaken for a scheme name. Such a segment must be > preceded by a dot-segment (e.g., "./this:that") to make a relative- > path reference. https://go-review.googlesource.com/27440 corrects the behavior for http.FileServer, but URL.String will still return an invalid URL. This CL reverts the changes to http.FileServer as they are unnecessary with this fix. Fixes #17184 Change-Id: I9211ae20f82c91b785d1b079b2cd766487d94225 Reviewed-on: https://go-review.googlesource.com/29610 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
cddddbc623
commit
ad5d91c17a
4 changed files with 60 additions and 15 deletions
|
|
@ -270,10 +270,11 @@ func TestFileServerEscapesNames(t *testing.T) {
|
|||
tests := []struct {
|
||||
name, escaped string
|
||||
}{
|
||||
{`simple_name`, `<a href="./simple_name">simple_name</a>`},
|
||||
{`"'<>&`, `<a href="./%22%27%3C%3E&">"'<>&</a>`},
|
||||
{`?foo=bar#baz`, `<a href="./%3Ffoo=bar%23baz">?foo=bar#baz</a>`},
|
||||
{`<combo>?foo`, `<a href="./%3Ccombo%3E%3Ffoo"><combo>?foo</a>`},
|
||||
{`simple_name`, `<a href="simple_name">simple_name</a>`},
|
||||
{`"'<>&`, `<a href="%22%27%3C%3E&">"'<>&</a>`},
|
||||
{`?foo=bar#baz`, `<a href="%3Ffoo=bar%23baz">?foo=bar#baz</a>`},
|
||||
{`<combo>?foo`, `<a href="%3Ccombo%3E%3Ffoo"><combo>?foo</a>`},
|
||||
{`foo:bar`, `<a href="./foo:bar">foo:bar</a>`},
|
||||
}
|
||||
|
||||
// We put each test file in its own directory in the fakeFS so we can look at it in isolation.
|
||||
|
|
@ -349,7 +350,7 @@ func TestFileServerSortsNames(t *testing.T) {
|
|||
t.Fatalf("read Body: %v", err)
|
||||
}
|
||||
s := string(b)
|
||||
if !strings.Contains(s, "<a href=\"./a\">a</a>\n<a href=\"./b\">b</a>") {
|
||||
if !strings.Contains(s, "<a href=\"a\">a</a>\n<a href=\"b\">b</a>") {
|
||||
t.Errorf("output appears to be unsorted:\n%s", s)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue