mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-17 05:10:40 -07:00
Ensure strip_html filter uses same regex as Ruby Liquid
This commit is contained in:
committed by
Jun Yang
parent
f668a5cc41
commit
8e9e10fdb4
+1
-1
@@ -66,7 +66,7 @@ var filters = {
|
||||
'sort': (v, arg) => v.sort(arg),
|
||||
'split': (v, arg) => stringify(v).split(arg),
|
||||
'strip': (v) => stringify(v).trim(),
|
||||
'strip_html': v => stringify(v).replace(/<\/?\s*\w+\s*\/?>/g, ''),
|
||||
'strip_html': v => stringify(v).replace(/<script.*?<\/script>|<!--.*?-->|<style.*?<\/style>|<.*?>/g, ''),
|
||||
'strip_newlines': v => stringify(v).replace(/\n/g, ''),
|
||||
'times': (v, arg) => v * arg,
|
||||
'truncate': (v, l, o) => {
|
||||
|
||||
+13
-1
@@ -301,9 +301,21 @@ describe('filters', function () {
|
||||
|
||||
describe('strip_html', function () {
|
||||
it('should strip all tags', function () {
|
||||
return test('{{ "Have <em>you</em> read <strong>Ulysses</strong>?" | strip_html }}',
|
||||
return test('{{ "Have <em>you</em> read <cite><a href="https://en.wikipedia.org/wiki/Ulysses_(novel)">Ulysses</a></cite>?" | strip_html }}',
|
||||
'Have you read Ulysses?')
|
||||
})
|
||||
it('should strip all comment tags', function () {
|
||||
return test('{{ "<!--Have you read-->Ulysses?" | strip_html }}',
|
||||
'Ulysses?')
|
||||
})
|
||||
it('should strip all style tags and their contents', function () {
|
||||
return test('{{ "<style>cite { font-style: italic; }</style><cite>Ulysses<cite>?" | strip_html }}',
|
||||
'Ulysses?')
|
||||
})
|
||||
it('should strip all scripts tags and their contents', function () {
|
||||
return test('{{ "<script async>console.log(\'hello world\')</script><cite>Ulysses<cite>?" | strip_html }}',
|
||||
'Ulysses?')
|
||||
})
|
||||
it('should strip until empty', function () {
|
||||
return test('{{"<br/><br />< p ></p></ p >" | strip_html }}', '')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user