Skip to content

Fix independent matches for stateful regexp walkers - #2170

Closed
xiehuanyi wants to merge 1 commit into
postcss:mainfrom
xiehuanyi:fix/stateful-regexp-walkers-20261013
Closed

xiehuanyi wants to merge 1 commit into
postcss:mainfrom
xiehuanyi:fix/stateful-regexp-walkers-20261013

Conversation

@xiehuanyi

@xiehuanyi xiehuanyi commented Oct 12, 2026 •

Copy link
Copy Markdown

Global and sticky regular expressions retain lastIndex between tests. The regexp forms of walkDecls(), walkRules(), and walkAtRules() therefore skip matching sibling nodes. For example, walking three color declarations with /color/g visits only the first and third declarations.

Reset stateful regexp matching before checking each candidate node. Add coverage for all three walkers with both flags, nested nodes, an initial nonzero lastIndex, and reusing the same regexp for another traversal.

Validation:

  • New regression cases on the unchanged source: 6 failures.
  • Full unit suite: 726 passed, with NO_COLOR unset and FORCE_COLOR=1 so the existing color-output tests use the requested mode.
  • pnpm test:lint, pnpm test:types, and pnpm test:size: pass. Built size 15.56 kB, under the 16.5 kB limit.
  • git diff --check: pass.

Discovery origin: this case was identified by automated OpenAI gpt-6.1-sol source review during this contribution. The evidence is the minimal API reproduction and the regression tests above; there is no production usage report. The same agent implemented and validated the patch with xhigh reasoning.

Copilot AI balanced review requested due to automatic review settings October 12, 2026 23:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9f7c71ef-5c26-4ff8-85d9-873d24e29517
📥 Commits

Reviewing files that changed from the base of the PR and between f1aca7e and 780ecf6.

📒 Files selected for processing (2)
  • lib/container.js
  • test/container.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

Walkthrough

The three container walk methods now reset global or sticky regular-expression state before testing filters. Tests cover repeated walks with both flags and a nonzero initial lastIndex.

Changes

Container walk matching

Layer / File(s) Summary
Reset regex state and test repeated walks
lib/container.js, test/container.test.ts
Added testRegExp and applied it to walkAtRules(), walkDecls(), and walkRules(). Tests verify that global and sticky filters visit all matching nodes on two consecutive passes.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 780ec

No actionable merge risk remains from the supplied changes; the PR is mergeable after normal checks.

Pre-merge checks · Passed 4 · Failed 1

Failed Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the fix for independent matches when walkers use stateful regular expressions.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ai

ai commented Oct 12, 2026

Copy link
Copy Markdown
Member

Is it you real use issue or LLM suggest you to fix this?

@xiehuanyi

Copy link
Copy Markdown
Author

@ai This was discovered by an LLM during a proactive source audit, not an issue I encountered in an application. I reproduced it through the public API: parsing a{color:red;color:blue}b{color:green} and calling walkDecls(/color/g, ...) visits red and green but skips blue; the patch visits all three. There is no production incident or external user report behind this PR.

@ai

ai commented Oct 15, 2026

Copy link
Copy Markdown
Member

Please don't find random issues with LLM. It is bad unethical practice.

It increases complexity by covering cases nobody want.

It is OK to send PRs where you are sure that somebody will need it.

@ai ai closed this Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants