Skip to content

Commit

Permalink
fix: stripComments bug that caused infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasPizsa committed Mar 8, 2022
1 parent 8f128d9 commit dbd9819
Show file tree
Hide file tree
Showing 3 changed files with 217 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hypertag.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ function parseAttrs(htmlTagText, tagKey = '<') {

function stripComments(html) {
// eslint-disable-next-line unicorn/better-regex
return html.replace(/<!--([\s]|.)*?-->/gims, '')
return html.replace(/<!--[\s\S]*?(?:-->)/gms, '')
}
201 changes: 201 additions & 0 deletions test/fixture-qualcomm.html

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions test/qualcomm.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const {readFileSync} = require('node:fs')
const {resolve} = require('node:path')
const test = require('ava')
const parse = require('../hypertag.js')
const {stripComments} = require('../hypertag.js')

const html = readFileSync(resolve(__dirname, './fixture-qualcomm.html'), 'utf-8')

test('it can strip comments from developer.qualcomm.com', t => {
t.notThrows(() => stripComments(html))
})

test('it can parse developer.qualcomm.com', t => {
t.notThrows(() => parse(html))
})

0 comments on commit dbd9819

Please # to comment.