Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pseudo-selectors/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function extendedFilter(tag: string[], range: string[]): boolean {
}

/** @see {@link https://www.w3.org/TR/selectors-4/#the-nth-child-pseudo} */
const nthOfRegex = /^(.+?)\s+of\s+(.+)$/is;
const nthOfRegex = /^(.+?\s)of\s+(.+)$/is;

/** A pre-compiled pseudo filter. */
export type Filter = <Node, ElementNode extends Node>(
Expand Down
7 changes: 7 additions & 0 deletions test/pseudo-classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ const dom = parseDOM(
"<div><p>In the end, it doesn't really Matter.</p><div>Indeed-that's a delicate matter.</div>",
) as Element[];

// The previous pattern backtracked on long whitespace, taking minutes here.
it("should reject a long whitespace nth argument without backtracking", () => {
expect(() =>
CSSselect.compile(`:nth-child(${" ".repeat(350_000)})`),
).toThrow("n-th rule couldn't be parsed");
}, 2000);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Measure the synchronous parse duration explicitly

If this regex regresses to synchronous backtracking again, the parser blocks the event loop, so Vitest cannot fire this 2-second timeout; the test eventually completes and passes once compile() throws, even if that takes minutes. Vitest's own reproduction confirms that synchronous work completing after a test timeout is still reported as passing. As a result, this test does not enforce the performance property described by its name and comment; measure elapsed time explicitly or run the parse in a worker/subprocess that can be terminated.

Useful? React with 👍 / 👎.


describe(":icontains", () => {
describe("ignore case", () => {
it("should match full string", () => {
Expand Down
Loading