Skip to content

Commit a8a8e55

Browse files
refactor: also consider unclosed comments
1 parent 2c60b35 commit a8a8e55

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

app/composables/useMarkdown.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ function stripAndEscapeHtml(text: string, packageName?: string): string {
3737
// Only match tags that start with a letter or / (to avoid matching things like "a < b > c")
3838
stripped = stripped.replace(/<\/?[a-z][^>]*>/gi, '')
3939

40-
// Strip HTML comments: <!-- ... -->
41-
stripped = stripped.replace(/<!--[\s\S]*?-->/g, '')
40+
// Strip HTML comments: <!-- ... --> (including unclosed comments from truncation)
41+
stripped = stripped.replace(/<!--[\s\S]*?(-->|$)/g, '')
4242

4343
if (packageName) {
4444
// Trim first to handle leading/trailing whitespace from stripped HTML

test/nuxt/composables/use-markdown.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,5 +344,10 @@ describe('useMarkdown', () => {
344344
const processed = useMarkdown({ text: '<!-- automd:badges color=yellow -->' })
345345
expect(processed.value).toBe('')
346346
})
347+
348+
it('strips unclosed HTML comments (truncated)', () => {
349+
const processed = useMarkdown({ text: 'A library <!-- automd:badges color=yel' })
350+
expect(processed.value).toBe('A library ')
351+
})
347352
})
348353
})

0 commit comments

Comments
 (0)