diff --git a/src/filters/html.ts b/src/filters/html.ts index 36b57b2a4..73be53cb6 100644 --- a/src/filters/html.ts +++ b/src/filters/html.ts @@ -32,5 +32,5 @@ export function newline_to_br (v: string) { } export function strip_html (v: string) { - return stringify(v).replace(/|||<.*?>/g, '') + return stringify(v).replace(/||<.*?>|/g, '') } diff --git a/test/e2e/issues.ts b/test/e2e/issues.ts index 4cb7dd388..d5d23455c 100644 --- a/test/e2e/issues.ts +++ b/test/e2e/issues.ts @@ -390,4 +390,14 @@ describe('Issues', function () { const html = await liquid.parseAndRender(tpl, ctx) expect(html.trim()).to.equal('Lot more code here') }) + it('#70 strip multiline content of ` + const engine = new Liquid() + const template = '{{ str | strip_html }}' + const html = await engine.parseAndRender(template, { str }) + expect(html).to.match(/^\s*$/) + }) }) diff --git a/test/integration/filters/html.ts b/test/integration/filters/html.ts index afe45b980..0ba5cc124 100644 --- a/test/integration/filters/html.ts +++ b/test/integration/filters/html.ts @@ -1,6 +1,10 @@ import { test } from '../../stub/render' +import { expect } from 'chai' +import { Liquid } from '../../../src/liquid' describe('filters/html', function () { + let liquid: Liquid + beforeEach(() => liquid = new Liquid()) describe('escape', function () { it('should escape \' and &', function () { return test('{{ "Have you read \'James & the Giant Peach\'?" | escape }}', @@ -43,14 +47,26 @@ describe('filters/html', function () { return test('{{ "Ulysses?" | strip_html }}', 'Ulysses?') }) + it('should strip multiline comments', function () { + expect(liquid.parseAndRenderSync('{{""|strip_html}}')).to.equal('') + }) it('should strip all style tags and their contents', function () { return test('{{ "Ulysses?" | strip_html }}', 'Ulysses?') }) + it('should strip multiline styles', function () { + expect(liquid.parseAndRenderSync('{{"" | strip_html}}')).to.equal('') + }) it('should strip all scripts tags and their contents', function () { return test('{{ "Ulysses?" | strip_html }}', 'Ulysses?') }) + it('should strip multiline scripts', function () { + expect(liquid.parseAndRenderSync('{{ "" | strip_html }}')).to.equal('') + }) + it('should not strip non-matched text" | strip_html }}')).to.equal('text') + }) it('should strip until empty', function () { return test('{{"

< p >

" | strip_html }}', '') })