diff --git a/src/Admin/Native/PostListEnhance.php b/src/Admin/Native/PostListEnhance.php index 9f3fc707..f0274c8f 100644 --- a/src/Admin/Native/PostListEnhance.php +++ b/src/Admin/Native/PostListEnhance.php @@ -347,12 +347,15 @@ class PostListEnhance { return ''; } - return $this->fields_html($fields, 'filter', __('高级筛选', 'aksrt'), __('让文章实现更加精细化的分类,同时方便用户进行文章筛选', 'aksrt')); + return $this->fields_html($fields, 'filter', __('高级筛选', 'aksrt'), '
' . esc_html__('让文章实现更加精细化的分类,同时方便用户进行文章筛选', 'aksrt') . '
'); } /** * Render one field group: the shared builder for every quick-edit box. * + * $desc 是调用方预先转义好的 HTML 片段,这里原样输出(付费参数那组 + * 自带
,转义会把标签显示成文字)。 + * * @param array> $fields */ private function fields_html(array $fields, string $id, string $title = '', string $desc = ''): string { @@ -430,8 +433,9 @@ class PostListEnhance { return ''; } + // $desc 由调用方传入并保证安全(均为代码内常量),故原样输出: + // 付费参数那组自带
,转义会让标签直接显示成文字。 $legend = $title !== '' ? '' . esc_html($title) . '' : ''; - $desc = $desc !== '' ? '
' . esc_html($desc) . '
' : ''; return '
' . $legend . '
' . $item_html . '
' . $desc . '
'; } diff --git a/tests/widget-system/post-list-quick-edit-contract.test.cjs b/tests/widget-system/post-list-quick-edit-contract.test.cjs index d2fd2545..b33d41f8 100644 --- a/tests/widget-system/post-list-quick-edit-contract.test.cjs +++ b/tests/widget-system/post-list-quick-edit-contract.test.cjs @@ -56,6 +56,17 @@ test('quick-edit markup is emitted without kses stripping the controls', () => { assert.match(list, /
{ + // 组描述由调用方预先转义后整体传入(付费参数那组自带
), + // 渲染处若再 esc_html,标签会直接显示成文字。 + assert.doesNotMatch(list, /esc_html\(\$desc\)/) + // 两个调用点都必须自带转义/HTML 包裹,不能传裸翻译串。 + assert.match(list, /'
' \. esc_html__\('批量设置付费参数/) + assert.match(list, /'
' \. 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`)