Skip to content

Commit 833dee0

Browse files
committed
fix bug where css parsing fails when attribute portion of selector comes first
1 parent 9eac5a6 commit 833dee0

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/ElementQueries.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@
179179
}
180180
}
181181

182-
var regex = /,?([^,\n]*?)\[[\s\t]*?(min|max)-(width|height)[\s\t]*?[~$\^]?=[\s\t]*?"([^"]*?)"[\s\t]*?]([^\n\s\{]*?)/mgi;
183-
182+
var regex = /,?[\s\t]*([^,\n]*?)((?:\[[\s\t]*?(?:min|max)-(?:width|height)[\s\t]*?[~$\^]?=[\s\t]*?"[^"]*?"[\s\t]*?])+)([^,\n\s\{]*)/mgi;
183+
var attrRegex = /\[[\s\t]*?(min|max)-(width|height)[\s\t]*?[~$\^]?=[\s\t]*?"([^"]*?)"[\s\t]*?]/mgi;
184184
/**
185185
* @param {String} css
186186
*/
@@ -189,9 +189,11 @@
189189
var smatch;
190190
css = css.replace(/'/g, '"');
191191
while (null !== (match = regex.exec(css))) {
192-
if (5 < match.length) {
193-
smatch = match[1] || match[5] || smatch;
194-
queueQuery(smatch, match[2], match[3], match[4]);
192+
smatch = match[1] + match[3];
193+
attrs = match[2];
194+
195+
while (null !== (attrMatch = attrRegex.exec(attrs))) {
196+
queueQuery(smatch, attrMatch[1], attrMatch[2], attrMatch[3]);
195197
}
196198
}
197199
}
@@ -235,7 +237,7 @@
235237
this.withTracking = withTracking;
236238
for (var i = 0, j = document.styleSheets.length; i < j; i++) {
237239
try {
238-
readRules(document.styleSheets[i].cssText || document.styleSheets[i].cssRules || document.styleSheets[i].rules);
240+
readRules(document.styleSheets[i].cssRules || document.styleSheets[i].rules || document.styleSheets[i].cssText);
239241
} catch(e) {
240242
if (e.name !== 'SecurityError') {
241243
throw e;

0 commit comments

Comments
 (0)