From 8e9e10fdb4c7f00ffa3997d3e2c0a0bfa48ce887 Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Tue, 8 May 2018 23:12:33 +0100 Subject: [PATCH] Ensure strip_html filter uses same regex as Ruby Liquid --- filters.js | 2 +- test/filters.js | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/filters.js b/filters.js index 1f5e9f373..37ae413ad 100644 --- a/filters.js +++ b/filters.js @@ -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(/|||<.*?>/g, ''), 'strip_newlines': v => stringify(v).replace(/\n/g, ''), 'times': (v, arg) => v * arg, 'truncate': (v, l, o) => { diff --git a/test/filters.js b/test/filters.js index c432423bb..51d34a5bc 100644 --- a/test/filters.js +++ b/test/filters.js @@ -301,9 +301,21 @@ describe('filters', function () { describe('strip_html', function () { it('should strip all tags', function () { - return test('{{ "Have you read Ulysses?" | strip_html }}', + return test('{{ "Have you read Ulysses?" | strip_html }}', 'Have you read Ulysses?') }) + it('should strip all comment tags', function () { + return test('{{ "Ulysses?" | strip_html }}', + 'Ulysses?') + }) + it('should strip all style tags and their contents', function () { + return test('{{ "Ulysses?" | strip_html }}', + 'Ulysses?') + }) + it('should strip all scripts tags and their contents', function () { + return test('{{ "Ulysses?" | strip_html }}', + 'Ulysses?') + }) it('should strip until empty', function () { return test('{{"

< p >

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