Skip to content

Commit b5d0046

Browse files
committed
fix(test): update parseSnippets HTML test to expect escaped preview
The snippets.ts refactor correctly added escapeHTML() to the preview for XSS protection. Update test to expect: - HTML entities escaped (<div> → &lt;div&gt;) - Newlines converted to <br/>
1 parent 9b75568 commit b5d0046

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/core/utils.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,10 @@ console.log("Hello, world!");
718718
t.truthy(testSnippet)
719719
if (testSnippet) {
720720
t.is(testSnippet.name, 'HTML Snippet')
721+
// text should remain unescaped (it's the actual snippet content to insert)
721722
t.is(testSnippet.text.trim(), '<div>\n <h1>Hello, world!</h1>\n</div>')
722-
const expectedPreview = `<div class="p-4">\n <style>\n p{\n margin-bottom: 1rem;\n }\n li{\n margin-bottom: .25rem;\n }\n \n </style>\n <div>\n <h1>Hello, world!</h1>\n</div>\n</div>`.trim()
723+
// preview should have escaped HTML for XSS safety (escapeHTML also converts \n to <br/>)
724+
const expectedPreview = `<div class="p-4">\n <style>\n p{\n margin-bottom: 1rem;\n }\n li{\n margin-bottom: .25rem;\n }\n\n </style>\n &lt;div&gt;<br/> &lt;h1&gt;Hello, world!&lt;/h1&gt;<br/>&lt;/div&gt;\n</div>`.trim()
723725
if (testSnippet.preview && typeof testSnippet.preview === 'string') {
724726
t.is(testSnippet.preview.replace(/\r\n/g, '\n').trim(), expectedPreview)
725727
}

0 commit comments

Comments
 (0)