首页 banner 站内链接自动补尾斜杠,避免多一次 301

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-29 15:46:21 +08:00
co-authored by Claude Opus 5.5
parent 1c5df7abbb
commit 3bc0069fb9
2 changed files with 54 additions and 0 deletions
@@ -0,0 +1,32 @@
package playletser
import "testing"
func TestNormalizeBannerURL(t *testing.T) {
cases := map[string]string{
"/detail/hqtqxdqe": "/detail/hqtqxdqe/",
"/detail/hqtqxdqe/": "/detail/hqtqxdqe/",
" /play/abc ": "/play/abc/",
"/detail/abc?from=banner": "/detail/abc/?from=banner",
"/": "/",
"": "",
"https://example.com/a": "https://example.com/a",
"//cdn.example.com/a": "//cdn.example.com/a",
"/static/images/a.png": "/static/images/a.png",
}
for in, want := range cases {
if got := normalizeBannerURL(in); got != want {
t.Errorf("normalizeBannerURL(%q) = %q, want %q", in, got, want)
}
}
}
func TestActiveHomeBannersNormalizesURL(t *testing.T) {
got := ActiveHomeBanners([]HomeBannerData{
{ID: 1, URL: "/detail/abc", Status: true},
{ID: 2, URL: "/detail/off", Status: false},
})
if len(got) != 1 || got[0].URL != "/detail/abc/" {
t.Fatalf("unexpected banners: %+v", got)
}
}