mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 04:40:39 -07:00
fix(strip_html): infinite loop for strip_html
This commit is contained in:
@@ -11,6 +11,7 @@ coverage/
|
|||||||
node_modules/
|
node_modules/
|
||||||
|
|
||||||
# tmp
|
# tmp
|
||||||
|
.local/
|
||||||
docs/themes/navy/source/js/liquid.browser.min.js
|
docs/themes/navy/source/js/liquid.browser.min.js
|
||||||
docs/themes/navy/layout/partial/all-contributors.swig
|
docs/themes/navy/layout/partial/all-contributors.swig
|
||||||
docs/themes/navy/layout/partial/financial-contributors.swig
|
docs/themes/navy/layout/partial/financial-contributors.swig
|
||||||
|
|||||||
@@ -6,6 +6,10 @@ title: strip_html
|
|||||||
|
|
||||||
Removes any HTML tags from a string.
|
Removes any HTML tags from a string.
|
||||||
|
|
||||||
|
{% note warn Not safe for HTML output %}
|
||||||
|
This filter removes tags by string scanning; it does not parse HTML5 the way a browser does, and it is not a sanitizer. The result may still be unsafe when inserted into HTML. Use [escape][escape], [escape_once][escape_once], or [`outputEscape: "escape"`][outputEscape] for untrusted output.
|
||||||
|
{% endnote %}
|
||||||
|
|
||||||
Input
|
Input
|
||||||
```liquid
|
```liquid
|
||||||
{{ "Have <em>you</em> read <strong>Ulysses</strong>?" | strip_html }}
|
{{ "Have <em>you</em> read <strong>Ulysses</strong>?" | strip_html }}
|
||||||
@@ -15,3 +19,7 @@ Output
|
|||||||
```text
|
```text
|
||||||
Have you read Ulysses?
|
Have you read Ulysses?
|
||||||
```
|
```
|
||||||
|
|
||||||
|
[escape]: ./escape.html
|
||||||
|
[escape_once]: ./escape.html
|
||||||
|
[outputEscape]: ../tutorials/options.html#outputEscape
|
||||||
|
|||||||
+1
-1
@@ -60,7 +60,7 @@ export function strip_html (this: FilterImpl, v: string) {
|
|||||||
if (e >= 0) { i = e + closer.length; break }
|
if (e >= 0) { i = e + closer.length; break }
|
||||||
blocks.delete(opener)
|
blocks.delete(opener)
|
||||||
}
|
}
|
||||||
if (i === lt) return out + str.slice(lt)
|
if (i <= lt) return out + str.slice(lt)
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,5 +85,9 @@ describe('filters/html', function () {
|
|||||||
expect(liquid.parseAndRenderSync('{{"<img\rsrc=x\ronerror=alert(1)>" | strip_html}}')).toBe('')
|
expect(liquid.parseAndRenderSync('{{"<img\rsrc=x\ronerror=alert(1)>" | strip_html}}')).toBe('')
|
||||||
expect(liquid.parseAndRenderSync('{{"<svg\nonload=alert(1)>" | strip_html}}')).toBe('')
|
expect(liquid.parseAndRenderSync('{{"<svg\nonload=alert(1)>" | strip_html}}')).toBe('')
|
||||||
})
|
})
|
||||||
|
it('should not loop on unclosed openers (GHSA-m7fp-h3p4-hr49)', function () {
|
||||||
|
expect(liquid.parseAndRenderSync('{{ "a<" | strip_html }}')).toBe('a<')
|
||||||
|
expect(liquid.parseAndRenderSync('{{ "hello<world<again" | strip_html }}')).toBe('hello<world<again')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user