Skip to content

Commit

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

function isEscaped(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) === "(" && !isEscaped(pos)) counter++;
else if(selector.charAt(pos) === ")" && !isEscaped(pos)) counter--;
}

if(counter){
Expand Down

0 comments on commit c636f0d

Please sign in to comment.