aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Liao <sean@liao.dev>2025-04-29 16:10:08 +0100
committerJonathan Amsterdam <jba@google.com>2025-05-08 08:04:49 -0700
commite476b3e609485f3999ebf60ee39b963e86e40e23 (patch)
tree5c45f3aefddc9cd3f1ea132dd14800d438183cc8
parent1bc9132f566501f5f66bfcb147479cf741704cf4 (diff)
downloadgo-x-pkgsite-e476b3e609485f3999ebf60ee39b963e86e40e23.tar.xz
internal/frontend: handle file paths with spaces
http.Handle generally handles the escaping for us, except for the first space which is used to split out the method. Fixes golang/go#73534 Change-Id: I588292ce5ffa6228f57c8e2c5f0ac5e73c27b853 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/668875 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> kokoro-CI: kokoro <noreply+kokoro@google.com>
-rw-r--r--internal/frontend/frontend_test.go4
-rw-r--r--internal/frontend/server.go2
2 files changed, 3 insertions, 3 deletions
diff --git a/internal/frontend/frontend_test.go b/internal/frontend/frontend_test.go
index 0533ed14..e2b01ba6 100644
--- a/internal/frontend/frontend_test.go
+++ b/internal/frontend/frontend_test.go
@@ -131,10 +131,10 @@ func TestTagRoute(t *testing.T) {
func TestInstallFS(t *testing.T) {
s, handler := newTestServer(t, nil)
- s.InstallFS("/dir", os.DirFS("."))
+ s.InstallFS("/a dir", os.DirFS("."))
// Request this file.
w := httptest.NewRecorder()
- handler.ServeHTTP(w, httptest.NewRequest("GET", "/files/dir/frontend_test.go", nil))
+ handler.ServeHTTP(w, httptest.NewRequest("GET", "/files/a%20dir/frontend_test.go", nil))
if w.Code != http.StatusOK {
t.Errorf("got status code = %d, want %d", w.Code, http.StatusOK)
}
diff --git a/internal/frontend/server.go b/internal/frontend/server.go
index 95522fc0..70c8a4ef 100644
--- a/internal/frontend/server.go
+++ b/internal/frontend/server.go
@@ -307,7 +307,7 @@ func (s *Server) installDebugHandlers(handle func(string, http.Handler)) {
// InstallFS adds path under the /files handler, serving the files in fsys.
func (s *Server) InstallFS(path string, fsys fs.FS) {
- s.fileMux.Handle(path+"/", http.StripPrefix(path, http.FileServer(http.FS(fsys))))
+ s.fileMux.Handle("GET "+path+"/", http.StripPrefix(path, http.FileServer(http.FS(fsys))))
}
const (