From f35628adff10f218101a334125e8640334bcd6db Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Wed, 27 Jun 2018 04:50:09 +0800 Subject: [PATCH] handle corner case when parsing DOCTYPE (#939) fixes #938 --- src/htmlparser.js | 2 +- tests/minifier.js | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/htmlparser.js b/src/htmlparser.js index 78e8928..12e35fb 100644 --- a/src/htmlparser.js +++ b/src/htmlparser.js @@ -60,7 +60,7 @@ var singleAttrIdentifier = /([^\s"'<>/=]+)/, startTagOpen = new RegExp('^<' + qnameCapture), startTagClose = /^\s*(\/?)>/, endTag = new RegExp('^<\\/' + qnameCapture + '[^>]*>'), - doctype = /^]+>/i; + doctype = /^]+>/i; var IS_REGEX_CAPTURING_BROKEN = false; 'x'.replace(/x(.)?/g, function(m, g) { diff --git a/tests/minifier.js b/tests/minifier.js index fe425f5..a3cf039 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -405,14 +405,21 @@ QUnit.test('types of whitespace that should always be preserved', function(asser QUnit.test('doctype normalization', function(assert) { var input; - input = ''; - assert.equal(minify(input, { useShortDoctype: true }), ''); - input = ''; + assert.equal(minify(input, { useShortDoctype: false }), input); assert.equal(minify(input, { useShortDoctype: true }), input); - input = ''; + input = ''; + assert.equal(minify(input, { useShortDoctype: false }), ''); + assert.equal(minify(input, { useShortDoctype: true }), ''); + + input = ''; assert.equal(minify(input, { useShortDoctype: false }), input); + assert.equal(minify(input, { useShortDoctype: true }), ''); + + input = ''; + assert.equal(minify(input, { useShortDoctype: false }), ''); + assert.equal(minify(input, { useShortDoctype: true }), ''); }); QUnit.test('removing comments', function(assert) { -- 2.34.1