修设置页主题色块被模板过滤器替换成 ZgotmplZ

html/template 对 style 属性做 CSS 过滤,linear-gradient(...) 未标记安全会被整体替换成
ZgotmplZ —— 线上设置页四个主题色块一直是灰底(既有问题,不是这次配色改动引入)。

- FuncMap 新增 safeCSS(string → template.CSS);值只来自 internal/theme.swatchOf,
  由两个已校验的色值拼成,不接受用户输入,所以这里放开是安全的
- user/profile.html 的色块改 {{ safeCSS .Swatch }}
- 新增 TestThemeSwatchRenders:渲染 user/profile,断言不含 ZgotmplZ 且含渐变串;
  已做变异验证(去掉 safeCSS 后该用例失败)
This commit is contained in:
tamakyi
2026-10-21 18:53:10 +08:00
parent 27856dd4a2
commit 1f29d3eb2e
4 changed files with 47 additions and 1 deletions
+7
View File
@@ -199,6 +199,13 @@ func FuncMap() []template.FuncMap {
"themeName": func(lang, slug string) string {
return theme.DisplayName(lang, slug)
},
// safeCSS 把受控的 CSS 值标成安全,用于主题色块的 inline background。
// ⚠️ html/template 会过滤 style 属性里的值,linear-gradient(...) 直接被替换成
// ZgotmplZ —— 设置页每个主题的色块都会变成灰底(线上就是这样)。
// 值只来自 internal/theme.swatchOf(由两个已校验的色值拼成),不接受用户输入。
"safeCSS": func(s string) template.CSS {
return template.CSS(s)
},
// moderationStrictness 返回账号「最终生效」的审核严格度档位(lax / standard / strict)。
//