Repository navigation
fix(pseudos): avoid overlapping whitespace in nth parsing - #1909
Conversation
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe ChangesNth-child whitespace parsing
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~8 minutes Change: Bug fix · Severity of issue fixed: Low Merge Risk: ⚪ Minimal · up to The change updates nth-of whitespace parsing and adds a targeted long-whitespace regression check. No material merge risk is identified in the supplied context. Pre-merge checks |
|
There was a problem hiding this comment.
🟢 Approval recommended
The focused regex change preserves parsing behavior while resolving the demonstrated performance issue with regression coverage.
0 open findings
What changed in this PR
Prevents excessive regex backtracking when parsing invalid :nth-child(... of ...) arguments.
Changes:
- Reworks
nthOfRegexto eliminate overlapping whitespace matching. - Adds a regression test using a long whitespace argument.
| File | Description |
|---|---|
src/pseudo-selectors/filters.ts |
Makes nth-of parsing fail efficiently. |
test/pseudo-classes.ts |
Verifies prompt rejection of pathological input. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b11676a0bc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| expect(() => | ||
| CSSselect.compile(`:nth-child(${" ".repeat(350_000)})`), | ||
| ).toThrow("n-th rule couldn't be parsed"); | ||
| }, 2000); |
There was a problem hiding this comment.
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 👍 / 👎.
|
The
:nth-child(… of …)argument was split with^(.+?)\s+of\s+(.+)$. Both.+?and\s+can claim the same whitespace, so an argument made of a long run of spaces made the engine try every split before giving up, taking seconds for a few thousand spaces.^(.+?\s)of\s+(.+)$lets the lazy group own the whitespace, so there is one way to match and failure is immediate.A test parses a 350,000-space argument and expects the parse error within a short timeout; on the previous pattern that input took minutes.
🤖 Generated with Claude Code
Summary by CodeRabbit
:nth-childexpressions with whitespace beforeof, preventing excessive delays on very long inputs.