From e2b30e900064373bce2f4ba4d3917df3de99ac69 Mon Sep 17 00:00:00 2001 From: Salman Aljammaz Date: Sun, 21 Aug 2016 16:59:56 +0100 Subject: [PATCH] net/http: prepend ./ to directory list hrefs in FileServer Certain browsers (Chrome 53, Safari 9.1.2, Firefox 46) won't correctly follow a directory listing's links if the file name begins with a run of characters then a colon, e.g. "foo:bar". Probably mistaking it for a URI. However, they are happy to follow "./foo:bar", so this change prepends "./" to all link hrefs in the directory listing of FileServer. Change-Id: I60ee8e1ebac73cbd3a3ac0f23e80fdf52e3dc352 Reviewed-on: https://go-review.googlesource.com/27440 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/net/http/fs.go | 2 +- src/net/http/fs_test.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/net/http/fs.go b/src/net/http/fs.go index c7a58a61df..9ebc558214 100644 --- a/src/net/http/fs.go +++ b/src/net/http/fs.go @@ -90,7 +90,7 @@ func dirList(w ResponseWriter, f File) { // part of the URL path, and not indicate the start of a query // string or fragment. url := url.URL{Path: name} - fmt.Fprintf(w, "%s\n", url.String(), htmlReplacer.Replace(name)) + fmt.Fprintf(w, "%s\n", url.String(), htmlReplacer.Replace(name)) } fmt.Fprintf(w, "\n") } diff --git a/src/net/http/fs_test.go b/src/net/http/fs_test.go index c811891e87..aa3323dd23 100644 --- a/src/net/http/fs_test.go +++ b/src/net/http/fs_test.go @@ -270,10 +270,10 @@ func TestFileServerEscapesNames(t *testing.T) { tests := []struct { name, escaped string }{ - {`simple_name`, `simple_name`}, - {`"'<>&`, `"'<>&`}, - {`?foo=bar#baz`, `?foo=bar#baz`}, - {`?foo`, `<combo>?foo`}, + {`simple_name`, `simple_name`}, + {`"'<>&`, `"'<>&`}, + {`?foo=bar#baz`, `?foo=bar#baz`}, + {`?foo`, `<combo>?foo`}, } // We put each test file in its own directory in the fakeFS so we can look at it in isolation. @@ -349,7 +349,7 @@ func TestFileServerSortsNames(t *testing.T) { t.Fatalf("read Body: %v", err) } s := string(b) - if !strings.Contains(s, "a\nb") { + if !strings.Contains(s, "a\nb") { t.Errorf("output appears to be unsorted:\n%s", s) } } -- 2.48.1