Skip to content

Commit bf93fc8

Browse files
committed
Merge pull request #510 from alexlamsl/issue-507
fix corner case in parser performance
2 parents b9e525d + e4db6af commit bf93fc8

File tree

4 files changed

+55
-28
lines changed

4 files changed

+55
-28
lines changed

‎dist/htmlminifier.js‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,37 +77,36 @@
7777
function startTagForHandler( handler ) {
7878
var customStartTagAttrs;
7979

80-
var startTagAttrs = new RegExp(
81-
'(?:\\s*[\\w:\\.-]+'
82-
+ '(?:\\s*'
83-
+ '(?:' + joinSingleAttrAssigns(handler) + ')'
84-
+ '\\s*(?:(?:"[^"]*")|(?:\'[^\']*\')|[^>\\s]+)'
85-
+ ')?'
86-
+ ')*'
80+
var startTagAttr = new RegExp(
81+
'[\\w:\\.-]+'
82+
+ '(?:\\s*'
83+
+ '(?:' + joinSingleAttrAssigns(handler) + ')'
84+
+ '\\s*(?:"[^"]*"+?|\'[^\']*\'+?|[^>\\s"\']+?)'
85+
+ ')?'
8786
);
8887

8988
if ( handler.customAttrSurround ) {
9089
var attrClauses = [];
9190

9291
for ( var i = handler.customAttrSurround.length - 1; i >= 0; i-- ) {
9392
// Capture the custom attribute opening and closing markup surrounding the standard attribute rules
94-
attrClauses[i] = '(?:\\s*'
93+
attrClauses[i] = '(?:'
9594
+ handler.customAttrSurround[i][0].source
9695
+ '\\s*'
97-
+ startTagAttrs.source
96+
+ startTagAttr.source
9897
+ '\\s*'
9998
+ handler.customAttrSurround[i][1].source
10099
+ ')';
101100
}
102-
attrClauses.unshift(startTagAttrs.source);
101+
attrClauses.unshift('(?:' + startTagAttr.source + ')');
103102

104103
customStartTagAttrs = new RegExp(
105-
'((?:' + attrClauses.join('|') + ')*)'
104+
'((?:\\s*(?:' + attrClauses.join('|') + '))*)'
106105
);
107106
}
108107
else {
109108
// No custom attribute wrappers specified, so just capture the standard attribute rules
110-
customStartTagAttrs = new RegExp('(' + startTagAttrs.source + ')');
109+
customStartTagAttrs = new RegExp('((?:\\s*' + startTagAttr.source + ')*)');
111110
}
112111

113112
return new RegExp(startTagOpen.source + customStartTagAttrs.source + startTagClose.source);

0 commit comments

Comments
 (0)