Repository navigation
Fix doubly nested parentheses in selectors throwing a recursion error - #122
Merged
Merged
Conversation
getPseudoClassString() advanced past the token after every nested parenthesised argument, so with two levels of nesting the outer argument never saw its closing paren and the scanner ran off the end of the input (issue #120). Quoted strings inside an argument are now read whole too, so a paren inside them no longer ends the argument. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #122 +/- ##
============================================
+ Coverage 90.69% 90.98% +0.28%
- Complexity 1424 1429 +5
============================================
Files 25 25
Lines 3170 3171 +1
============================================
+ Hits 2875 2885 +10
+ Misses 295 286 -9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A selector with two levels of nested parentheses threw from the scanner:
Cause
Scanner::getPseudoClassString()reads a nested(...)with a recursive call, and that call already consumes the closing). The outer loop then callednextToken()again and skipped one more character. With one level of nesting, the skipped character was the outer). That only went unnoticed when the selector ended there:li:not(:nth-child(1)) bparsed asli:not(":nth-child(1) b"). With two levels, the outer argument never saw its)and the scanner read past the end.find()andremove()share this scanner, so both engines threw.Change
nextToken()after a nested argument.:contains("a)b")no longer ends at the quoted paren, and:contains("a(b)")keeps its closing quote.The change is confined to
src/CSS/Scanner.php. The parser and both engines are untouched.Tests
ParserTest: the value passed topseudoClass()for every selector in the issue's table, plus three levels of nesting, quoted and unquoted arguments containing parens, and a selector that continues after a nested argument (li:not(:nth-child(1)) b).DOMQueryTest:find()andremove()results for the same selectors.:has()is checked only through the parser andremove(), becausefind()never matches:has()(:has()never matches in find():qp($xml)->find('ul:has(li)')returns nothing #121).:matches()and:eq()are checked only throughfind(). The legacy engine doesn't support:matches(), and it evaluates:eq()inside:not()per element:remove('li:not(:eq(0))')already removes nothing onmain.24 of the new cases fail on
main.Behaviour change
Selectors that continue after a nested argument (
li:not(:nth-child(1)) b,p:not(:has(a)).x) now apply the trailing part as a separate selector step. Before, it was folded into the pseudo-class argument.Fixes #120.
🤖 Generated with Claude Code