Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/htmlminifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -869,9 +869,9 @@ function minify(value, options, partialMarkup) {
return re.source;
});
if (customFragments.length) {
var reCustomIgnore = new RegExp('(\\s*)(?:' + customFragments.join('|') + ')+(\\s*)', 'g');
var reCustomIgnore = new RegExp('\\s*(?:' + customFragments.join('|') + ')+\\s*', 'g');
// temporarily replace custom ignored fragments with unique attributes
value = value.replace(reCustomIgnore, function(match, prefix, suffix) {
value = value.replace(reCustomIgnore, function(match) {
if (!uidAttr) {
uidAttr = uniqueId(value);
uidPattern = new RegExp('(\\s*)' + uidAttr + '([0-9]+)(\\s*)', 'g');
Expand All @@ -889,7 +889,7 @@ function minify(value, options, partialMarkup) {
}
}
var token = uidAttr + ignoredCustomMarkupChunks.length;
ignoredCustomMarkupChunks.push([match, prefix, suffix]);
ignoredCustomMarkupChunks.push(/^(\s*)[\s\S]*?(\s*)$/.exec(match));
return '\t' + token + '\t';
});
}
Expand Down
12 changes: 12 additions & 0 deletions tests/minifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -1813,6 +1813,18 @@ QUnit.test('Ignore custom fragments', function(assert) {
collapseWhitespace: true,
trimCustomFragments: true
}), output);

input = 'foo <WC@bar> baz moo </WC@bar> loo';
assert.equal(minify(input, {
collapseWhitespace: true,
ignoreCustomFragments: [
/<(WC@[\s\S]*?)>(.*?)<\/\1>/
]
}), input);
output = 'foo<wc @bar>baz moo</wc>loo';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output must preserve both tags like input:

probably as follow:

output = 'foo<WC@bar>baz moo</WC@bar>loo';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the case without ignoreCustomFragments - the case you are interested in is a line above, when nothing's changed, i.e. expects to equal to input 😉

assert.equal(minify(input, {
collapseWhitespace: true
}), output);
});

QUnit.test('bootstrap\'s span > button > span', function(assert) {
Expand Down