Skip to content

Commit

Permalink
Allow escaped parentheses in pseudo selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
DShadrick committed Feb 22, 2018
1 parent 4e255c9 commit de002d1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions index.js
Expand Up @@ -104,6 +104,13 @@ function parseSelector(subselects, selector, options){
selector = selector.substr(start);
}

function checkEscaped(pos) {
var slashCount = 0;

while (selector.charAt(--pos) === "\\") slashCount++;
return (slashCount & 1) === 1;
}

stripWhitespace(0);

while(selector !== ""){
Expand Down Expand Up @@ -211,8 +218,8 @@ function parseSelector(subselects, selector, options){
var pos = 1, counter = 1;

for(; counter > 0 && pos < selector.length; pos++){
if(selector.charAt(pos) === "(") counter++;
else if(selector.charAt(pos) === ")") counter--;
if(selector.charAt(pos) === "(" && !checkEscaped(pos)) counter++;
else if(selector.charAt(pos) === ")" && !checkEscaped(pos)) counter--;
}

if(counter){
Expand Down

0 comments on commit de002d1

Please sign in to comment.