Compare commits

...
1 Commits
Author SHA1 Message Date
terminarandClaude Opus 5.5 148062ec28 ApplyAppearance: cut BasePath only as a whole path segment
Behind http.StripPrefix the request path is already relative, and a
blind TrimPrefix turned /release-notes into "elease-notes" for
BasePath /r, sending the menu back to the start page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 23:00:50 +01:00
2 changed files with 20 additions and 1 deletions

No files matched your search

+11 -1
View File
@@ -67,7 +67,17 @@ func (h *PageHeader) ApplyAppearance(r *http.Request) {
if c, err := r.Cookie(PaletteCookie); err == nil && known(Palettes, c.Value) { if c, err := r.Cookie(PaletteCookie); err == nil && known(Palettes, c.Value) {
h.Palette = c.Value h.Palette = c.Value
} }
back := url.URL{Path: strings.TrimPrefix(r.URL.Path, h.BasePath), RawQuery: r.URL.RawQuery} // Only a whole leading BasePath segment is cut: behind
// http.StripPrefix the path is already relative, and "/r" must not
// eat the start of "/release-notes".
path := r.URL.Path
if h.BasePath != "" && (path == h.BasePath || strings.HasPrefix(path, h.BasePath+"/")) {
path = strings.TrimPrefix(path, h.BasePath)
}
if path == "" {
path = "/"
}
back := url.URL{Path: path, RawQuery: r.URL.RawQuery}
h.AppearanceBack = back.String() h.AppearanceBack = back.String()
} }
+9
View File
@@ -142,6 +142,15 @@ func TestApplyAppearance(t *testing.T) {
if h.AppearanceBack != "/tasks?f=1" { if h.AppearanceBack != "/tasks?f=1" {
t.Errorf("AppearanceBack = %q, want %q", h.AppearanceBack, "/tasks?f=1") t.Errorf("AppearanceBack = %q, want %q", h.AppearanceBack, "/tasks?f=1")
} }
// Behind http.StripPrefix the path is already relative to BasePath.
for path, want := range map[string]string{"/release-notes": "/release-notes", "/r": "/", "/r/x": "/x"} {
h := PageHeader{BasePath: "/r"}
h.ApplyAppearance(httptest.NewRequest(http.MethodGet, path, nil))
if h.AppearanceBack != want {
t.Errorf("BasePath /r, path %s: AppearanceBack = %q, want %q", path, h.AppearanceBack, want)
}
}
} }
func TestAppearanceHandler(t *testing.T) { func TestAppearanceHandler(t *testing.T) {