Skip to content

Commit

Permalink
fix(parse): Disallow quotes around unpacked pseudos
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 committed Oct 12, 2020
1 parent f07d582 commit 276a4b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const broken = [
"[id=012345678901234567890123456789",
"input[name=foo.baz]",
"input[name=foo[baz]]",
':has("p")',
];

describe("Broken selectors", () => {
Expand Down
17 changes: 6 additions & 11 deletions src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})`
Expand Down

0 comments on commit 276a4b2

Please sign in to comment.