[READ-ONLY] a fast, modern browser for the npm registry

fix: remove html comments from package description and deprecation notices (#1397)

authored by

Alexander Lichter and committed by
GitHub
a81faa9a c37a3218

+35
+3
app/composables/useMarkdown.ts
··· 37 37 // Only match tags that start with a letter or / (to avoid matching things like "a < b > c") 38 38 stripped = stripped.replace(/<\/?[a-z][^>]*>/gi, '') 39 39 40 + // Strip HTML comments: <!-- ... --> (including unclosed comments from truncation) 41 + stripped = stripped.replace(/<!--[\s\S]*?(-->|$)/g, '') 42 + 40 43 if (packageName) { 41 44 // Trim first to handle leading/trailing whitespace from stripped HTML 42 45 stripped = stripped.trim()
+32
test/nuxt/composables/use-markdown.spec.ts
··· 318 318 expect(processed.value).toBe('bold and <strong>also bold</strong>') 319 319 }) 320 320 }) 321 + 322 + describe('HTML comment stripping', () => { 323 + it('strips HTML comments', () => { 324 + const processed = useMarkdown({ text: '<!-- automd:badges color=yellow -->A library' }) 325 + expect(processed.value).toBe('A library') 326 + }) 327 + 328 + it('strips HTML comments from the middle of text', () => { 329 + const processed = useMarkdown({ text: 'Before <!-- comment --> after' }) 330 + expect(processed.value).toBe('Before after') 331 + }) 332 + 333 + it('strips multiple HTML comments', () => { 334 + const processed = useMarkdown({ text: '<!-- first -->Text <!-- second -->here' }) 335 + expect(processed.value).toBe('Text here') 336 + }) 337 + 338 + it('strips multiline HTML comments', () => { 339 + const processed = useMarkdown({ text: '<!-- multi\nline\ncomment -->Text' }) 340 + expect(processed.value).toBe('Text') 341 + }) 342 + 343 + it('returns empty string when description is only a comment', () => { 344 + const processed = useMarkdown({ text: '<!-- automd:badges color=yellow -->' }) 345 + expect(processed.value).toBe('') 346 + }) 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 + }) 352 + }) 321 353 })