diff --git a/src/parse.spec.ts b/src/parse.spec.ts index 904bc141..0fe2e2c3 100644 --- a/src/parse.spec.ts +++ b/src/parse.spec.ts @@ -32,6 +32,7 @@ const broken = [ "[id=012345678901234567890123456789", "input[name=foo.baz]", "input[name=foo[baz]]", + ':has("p")', ]; describe("Broken selectors", () => { diff --git a/src/parse.ts b/src/parse.ts index 2b1ad3b6..3e28fa1e 100644 --- a/src/parse.ts +++ b/src/parse.ts @@ -311,22 +311,17 @@ function parseSelector( if (selector.startsWith("(")) { if (unpackPseudos.has(name)) { - const quot = selector.charAt(1); - const quoted = quotes.has(quot); + if (quotes.has(selector.charAt(1))) { + throw new Error( + `Pseudo-selector ${name} cannot be quoted` + ); + } - selector = selector.substr(quoted ? 2 : 1); + selector = selector.substr(1); data = []; selector = parseSelector(data, selector, options); - if (quoted) { - if (!selector.startsWith(quot)) { - throw new Error(`Unmatched quotes in :${name}`); - } else { - selector = selector.substr(1); - } - } - if (!selector.startsWith(")")) { throw new Error( `Missing closing parenthesis in :${name} (${selector})`