修设置页主题色块被模板过滤器替换成 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
+1 -1
View File
@@ -804,7 +804,7 @@
{{ range .Themes }}
<label class="tb-theme-opt">
<input class="uk-radio" type="radio" name="theme" value="{{ .Slug }}"{{ if eq $.CurrentTheme .Slug }} checked{{ end }}>
<span class="tb-theme-swatch"{{ if .Swatch }} style="background: {{ .Swatch }}"{{ end }}></span>
<span class="tb-theme-swatch"{{ if .Swatch }} style="background: {{ safeCSS .Swatch }}"{{ end }}></span>
<span class="tb-theme-name">{{ themeName $.LangCode .Slug }}</span>
</label>
{{ end }}