fix(admin): 修复快捷编辑组描述被 esc_html 转义成可见标签
「付费参数」组的说明文字 `<div class="c-yellow">…</div>` 整段被显示 成了纯文本标签。原因:fields_html() 对 $desc 做了 esc_html(),而该 参数传入的是一段自带 <div> 的 HTML,转义后标签就变成了可见字符。 改为按参考主题的做法原样输出 $desc,责任前移到调用方: - pay 组:esc_html__() 转义文字,外层 div 由模板给出; - filter 组:同样自带 <div class="px12 aksrt-bulk-edit-desc"> 包裹, 以保住原有样式(此前样式靠 fields_html 里的外层 div 提供)。 字段标题仍保持 esc_html(),因为 filter 那组的标题来自设置项。 新增契约断言锁住这个契约:不得再 esc_html($desc),两个调用点必须 各自转义/包裹;同时保留「字段标题仍转义」的断言。 验证:node --test tests/widget-system/*.test.cjs 445 项全部通过 (原有 444 项 + 新增 1 项);php -l 无语法错误。
This commit is contained in:
@@ -56,6 +56,17 @@ test('quick-edit markup is emitted without kses stripping the controls', () => {
|
||||
assert.match(list, /<fieldset/)
|
||||
assert.match(list, /edit_boxes_html\(\)/)
|
||||
})
|
||||
|
||||
test('field-group descriptions are emitted as pre-escaped HTML', () => {
|
||||
// 组描述由调用方预先转义后整体传入(付费参数那组自带 <div class="c-yellow">),
|
||||
// 渲染处若再 esc_html,标签会直接显示成文字。
|
||||
assert.doesNotMatch(list, /esc_html\(\$desc\)/)
|
||||
// 两个调用点都必须自带转义/HTML 包裹,不能传裸翻译串。
|
||||
assert.match(list, /'<div class="c-yellow">' \. esc_html__\('批量设置付费参数/)
|
||||
assert.match(list, /'<div class="px12 aksrt-bulk-edit-desc">' \. esc_html__\('让文章实现更加精细化/)
|
||||
// 仍来自设置项的字段标题必须保持转义。
|
||||
assert.match(list, /esc_html\(\$title_html\)/)
|
||||
})
|
||||
test('number fields support the full operation set', () => {
|
||||
for (const op of ['ignore', 'set', 'plus', 'subtract', 'multiply', 'division']) {
|
||||
assert.match(list, new RegExp(`value="${op}"`), `${op} operation exists`)
|
||||
|
||||
Reference in New Issue
Block a user