Skip to content

Commit

Permalink
fix corner case in decodeEntities (#894)
Browse files Browse the repository at this point in the history
fixes #893
  • Loading branch information
alexlamsl authored Mar 19, 2018
1 parent 6062467 commit 68981b7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/htmlminifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -1153,11 +1153,6 @@ function minify(value, options, partialMarkup) {
trimTrailingWhitespace(buffer.length - 1, nextTag);
}
}
else if (uidPattern) {
text = text.replace(uidPattern, function(match, prefix, index) {
return ignoredCustomMarkupChunks[+index][0];
});
}
if (!stackNoCollapseWhitespace.length && nextTag !== 'html' && !(prevTag && nextTag)) {
text = collapseWhitespace(text, options, false, false, true);
}
Expand Down Expand Up @@ -1191,6 +1186,11 @@ function minify(value, options, partialMarkup) {
// https://mathiasbynens.be/notes/ambiguous-ampersands
text = text.replace(/&(#?[0-9a-zA-Z]+;)/g, '&amp$1').replace(/</g, '&lt;');
}
if (uidPattern && options.collapseWhitespace && stackNoTrimWhitespace.length) {
text = text.replace(uidPattern, function(match, prefix, index) {
return ignoredCustomMarkupChunks[+index][0];
});
}
currentChars += text;
if (text) {
hasChars = true;
Expand Down
8 changes: 8 additions & 0 deletions tests/minifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -3250,6 +3250,14 @@ QUnit.test('decode entity characters', function(assert) {
assert.equal(minify(input, { decodeEntities: false }), input);
output = '<a href="/?foo=1&bar=<2>">baz&lt;moo>\u00a9</a>';
assert.equal(minify(input, { decodeEntities: true }), output);

input = '<? &amp; ?>&amp;<pre><? &amp; ?>&amp;</pre>';
assert.equal(minify(input), input);
assert.equal(minify(input, { collapseWhitespace: false, decodeEntities: false }), input);
assert.equal(minify(input, { collapseWhitespace: true, decodeEntities: false }), input);
output = '<? &amp; ?>&<pre><? &amp; ?>&</pre>';
assert.equal(minify(input, { collapseWhitespace: false, decodeEntities: true }), output);
assert.equal(minify(input, { collapseWhitespace: true, decodeEntities: true }), output);
});

QUnit.test('tests from PHPTAL', function(assert) {
Expand Down

0 comments on commit 68981b7

Please sign in to comment.