Skip to content

Commit 885c27f

Browse files
author
Eric Wheeler
committed
test: update CodeBlock tests to support codeToHast
Updated the CodeBlock test mock to support the new codeToHast method that was implemented to fix the XSS vulnerability by replacing dangerouslySetInnerHTML with direct React element rendering. Signed-off-by: Eric Wheeler <[email protected]>
1 parent e1fc1aa commit 885c27f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

webview-ui/src/components/common/__tests__/CodeBlock.spec.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,28 @@ vi.mock("../../../utils/highlighter", () => {
3737
const theme = options.theme === "github-light" ? "light" : "dark"
3838
return `<pre><code class="hljs language-${options.lang}">${code} [${theme}-theme]</code></pre>`
3939
}),
40+
codeToHast: vi.fn().mockImplementation((code, options) => {
41+
const theme = options.theme === "github-light" ? "light" : "dark"
42+
// Return a simple HAST node structure that includes the theme marker
43+
return {
44+
type: "element",
45+
tagName: "pre",
46+
properties: {},
47+
children: [
48+
{
49+
type: "element",
50+
tagName: "code",
51+
properties: { className: [`hljs`, `language-${options.lang}`] },
52+
children: [
53+
{
54+
type: "text",
55+
value: `${code} [${theme}-theme]`,
56+
},
57+
],
58+
},
59+
],
60+
}
61+
}),
4062
}
4163

4264
return {

0 commit comments

Comments
 (0)