diff --git a/src/filters/html.ts b/src/filters/html.ts
index 90a83f096..c44ef92da 100644
--- a/src/filters/html.ts
+++ b/src/filters/html.ts
@@ -42,32 +42,28 @@ export function newline_to_br (this: FilterImpl, v: string) {
return str.replace(/\r?\n/gm, '
\n')
}
-// Linear-time replacement for the previous backtracking regex
+// Linear-time strip via indexOf scan. A regex equivalent to the old
// /'], [' position" across openers.
export function strip_html (this: FilterImpl, v: string) {
const str = stringify(v)
this.context.memoryLimit.use(str.length)
- const closers = [0, 0]
let out = ''
let i = 0
+ let scriptEnd = 0
+ let styleEnd = 0
while (i < str.length) {
const lt = str.indexOf('<', i)
if (lt < 0) return out + str.slice(i)
out += str.slice(i, lt)
let end = -1
- for (let k = 0; k < STRIP_BLOCKS.length; k++) {
- const [opener, closer] = STRIP_BLOCKS[k]
- if (!str.startsWith(opener, lt)) continue
- const from = lt + opener.length
- if (closers[k] !== -1 && closers[k] < from) closers[k] = str.indexOf(closer, from)
- if (closers[k] >= 0) end = closers[k] + closer.length
- break
+ if (str.startsWith('', lt + 7)
+ if (scriptEnd >= 0) end = scriptEnd + 9
+ } else if (str.startsWith('', lt + 6)
+ if (styleEnd >= 0) end = styleEnd + 8
}
if (end < 0) end = str.indexOf('>', lt + 1) + 1
if (end <= 0) return out + str.slice(lt)