diff --git a/src/filters/html.ts b/src/filters/html.ts
index fb8096aef..e59adfd58 100644
--- a/src/filters/html.ts
+++ b/src/filters/html.ts
@@ -42,16 +42,11 @@ export function newline_to_br (this: FilterImpl, v: string) {
return str.replace(/\r?\n/gm, '
\n')
}
-// '], [''], ['']])
let out = ''
let i = 0
while (i < str.length) {
@@ -59,12 +54,12 @@ export function strip_html (this: FilterImpl, v: string) {
if (lt < 0) return out + str.slice(i)
out += str.slice(i, lt)
let end = -1
- for (let k = 0; k < blocks.length; k++) {
- const [opener, closer] = blocks[k]
+ for (const block of blocks) {
+ const [opener, closer] = block
if (!str.startsWith(opener, lt)) continue
- const from = lt + opener.length
- if (closes[k] >= 0 && closes[k] < from) closes[k] = str.indexOf(closer, from)
- if (closes[k] >= 0) end = closes[k] + closer.length
+ const e = str.indexOf(closer, lt + opener.length)
+ if (e < 0) blocks.delete(block)
+ else end = e + closer.length
break
}
if (end < 0) end = str.indexOf('>', lt + 1) + 1
diff --git a/test/integration/liquid/dos.spec.ts b/test/integration/liquid/dos.spec.ts
index 4b6cfd0df..85783564e 100644
--- a/test/integration/liquid/dos.spec.ts
+++ b/test/integration/liquid/dos.spec.ts
@@ -88,29 +88,21 @@ describe('DoS related', function () {
describe('strip_html ReDoS', () => {
// Regression for O(n^2) backtracking on unclosed ` in linear time', () => {
const liquid = new Liquid()
const payload = '