diff --git a/lib/utils.js b/lib/utils.js index f1e736f..3432b1a 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -3,8 +3,8 @@ const entities = require('entities'); const xml2js = require('xml2js'); utils.stripHtml = function(str) { - str = str.replace(/([^\n])<\/?(h|br|p|ul|ol|li|blockquote|section|table|tr|div)(?:.|\n)*?>([^\n])/gm, '$1\n$3') - str = str.replace(/<(?:.|\n)*?>/gm, ''); + str = str.replace(/([^\n])<\/?(h|br|p|ul|ol|li|blockquote|section|table|tr|div)[^<>]*>([^\n])/gm, '$1\n$3') + str = str.replace(/<[^<>]*>/gm, ''); return str; } diff --git a/test/html.js b/test/html.js index b93ffb9..84948b5 100644 --- a/test/html.js +++ b/test/html.js @@ -41,5 +41,11 @@ describe('Utils', function() { Expect('|' + utils.getSnippet(tc.input) + '|').to.equal('|' + tc.output + '|', tc.input); }); }) + + it('should handle repeated unterminated HTML tags efficiently', function() { + this.timeout(2000); + var input = 'a