首页 banner 站内链接自动补尾斜杠,避免多一次 301
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user