From: Alex Lam S.L Date: Sat, 30 Jul 2016 07:58:35 +0000 (+0900) Subject: fix interaction between htmlmin:ignore & ignoreCustomComments (#699) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=72678b6dbbca01b5473f864fbac188b1196ae178;p=html-minifier.git fix interaction between htmlmin:ignore & ignoreCustomComments (#699) fixes #696 --- diff --git a/src/htmlminifier.js b/src/htmlminifier.js index f25b1d0..2a6f3f7 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -845,8 +845,15 @@ function minify(value, options, partialMarkup) { value = value.replace(/([\s\S]*?)/g, function(match, group1) { if (!uidIgnore) { uidIgnore = uniqueId(value); + var pattern = new RegExp('^' + uidIgnore + '([0-9]+)$'); + if (options.ignoreCustomComments) { + options.ignoreCustomComments.push(pattern); + } + else { + options.ignoreCustomComments = [pattern]; + } } - var token = ''; + var token = ''; ignoredMarkupChunks.push(group1); return token; }); @@ -1254,7 +1261,7 @@ function minify(value, options, partialMarkup) { }); } if (uidIgnore) { - str = str.replace(new RegExp('', 'g'), function(match, index) { + str = str.replace(new RegExp('', 'g'), function(match, index) { return ignoredMarkupChunks[+index]; }); } diff --git a/tests/minifier.js b/tests/minifier.js index 5df325c..61c8ec2 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -2247,10 +2247,36 @@ QUnit.test('collapse inline tag whitespace', function(assert) { }); QUnit.test('ignore custom comments', function(assert) { - var input; + var input, output; - input = '
  • test
  • '; + input = ''; + assert.equal(minify(input), input); + assert.equal(minify(input, { removeComments: true }), input); + assert.equal(minify(input, { ignoreCustomComments: false }), input); + assert.equal(minify(input, { + removeComments: true, + ignoreCustomComments: [] + }), ''); + assert.equal(minify(input, { + removeComments: true, + ignoreCustomComments: false + }), ''); + input = 'test'; + output = 'test'; + assert.equal(minify(input), output); + assert.equal(minify(input, { removeComments: true }), output); + assert.equal(minify(input, { ignoreCustomComments: false }), output); + assert.equal(minify(input, { + removeComments: true, + ignoreCustomComments: [] + }), output); + assert.equal(minify(input, { + removeComments: true, + ignoreCustomComments: false + }), output); + + input = '
  • test
  • '; assert.equal(minify(input, { removeComments: true, // ignore knockout comments @@ -2261,7 +2287,6 @@ QUnit.test('ignore custom comments', function(assert) { }), input); input = ''; - assert.equal(minify(input, { removeComments: true, // ignore Apache SSI includes