Skip to content

Commit e476b3e

Browse files
seankhliaojba
authored andcommitted
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 <[email protected]> Reviewed-by: Cherry Mui <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> kokoro-CI: kokoro <[email protected]>
1 parent 1bc9132 commit e476b3e

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

internal/frontend/frontend_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ func TestTagRoute(t *testing.T) {
131131

132132
func TestInstallFS(t *testing.T) {
133133
s, handler := newTestServer(t, nil)
134-
s.InstallFS("/dir", os.DirFS("."))
134+
s.InstallFS("/a dir", os.DirFS("."))
135135
// Request this file.
136136
w := httptest.NewRecorder()
137-
handler.ServeHTTP(w, httptest.NewRequest("GET", "/files/dir/frontend_test.go", nil))
137+
handler.ServeHTTP(w, httptest.NewRequest("GET", "/files/a%20dir/frontend_test.go", nil))
138138
if w.Code != http.StatusOK {
139139
t.Errorf("got status code = %d, want %d", w.Code, http.StatusOK)
140140
}

internal/frontend/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ func (s *Server) installDebugHandlers(handle func(string, http.Handler)) {
307307

308308
// InstallFS adds path under the /files handler, serving the files in fsys.
309309
func (s *Server) InstallFS(path string, fsys fs.FS) {
310-
s.fileMux.Handle(path+"/", http.StripPrefix(path, http.FileServer(http.FS(fsys))))
310+
s.fileMux.Handle("GET "+path+"/", http.StripPrefix(path, http.FileServer(http.FS(fsys))))
311311
}
312312

313313
const (

0 commit comments

Comments
 (0)