From 7e8406e3244d09197f440b5ef1736e99e2c37c13 Mon Sep 17 00:00:00 2001 From: Mathias Bynens Date: Fri, 5 Oct 2018 16:09:27 +0200 Subject: [PATCH] Use (without the space) where possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When both the `useShortDoctype` and the `removeTagWhitespace` options are enabled, we can remove the space from the doctype altogether. It’s invalid HTML (which is already expected in the output with the `removeTagWhitespace` option enabled), but it still triggers standards mode. https://html.spec.whatwg.org/multipage/parsing.html#parse-error-missing-whitespace-before-doctype-name https://twitter.com/mathias/status/1048098677703753729 Closes #969. --- src/htmlminifier.js | 4 +++- tests/minifier.js | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 9fe9e078..dccf4ca2 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -1235,7 +1235,9 @@ function minify(value, options, partialMarkup) { buffer.push(text); }, doctype: function(doctype) { - buffer.push(options.useShortDoctype ? '' : collapseWhitespaceAll(doctype)); + buffer.push(options.useShortDoctype ? '' : + collapseWhitespaceAll(doctype)); }, customAttrAssign: options.customAttrAssign, customAttrSurround: options.customAttrSurround diff --git a/tests/minifier.js b/tests/minifier.js index 30502d29..08dc657a 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -410,6 +410,11 @@ QUnit.test('doctype normalization', function(assert) { assert.equal(minify(input, { useShortDoctype: false }), input); assert.equal(minify(input, { useShortDoctype: true }), output); + assert.equal(minify(input, { + useShortDoctype: true, + removeTagWhitespace: true + }), ''); + input = ''; assert.equal(minify(input, { useShortDoctype: false }), ''); assert.equal(minify(input, { useShortDoctype: true }), output);