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>
This commit is contained in:
terminarandClaude Opus 5.5 committed 2026-10-29 23:00:50 +01:00
1 parent 3af449e9f9
commit 148062ec28
2 files changed
+20 -1

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) {
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()
}