Repository navigation
Reject :scope after a comma in :has() arguments - #210
Merged
Merged
Conversation
The :scope check treats a preceding comma as the start of a new selector, but inside :has() a comma separates relative selectors. :has(:scope) was rejected while a:has(b, :scope) was accepted and translated to "any descendant element", like :is() before scrapy#168.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #210 +/- ##
=======================================
Coverage 99.80% 99.80%
=======================================
Files 3 3
Lines 1002 1002
Branches 167 167
=======================================
Hits 1000 1000
Misses 1 1
Partials 1 1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
AdrianAtZyte
approved these changes
Oct 20, 2026
wRAR
approved these changes
Oct 20, 2026
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.
:scopeafter a comma inside:has()is accepted and mistranslatedparse_simple_selector()only accepts:scopewhen the token before its compound selector is the start of the input or a comma. #168 made:is()/:where()/:matches()passinside_selector_listbecause a comma there separates arguments, butparse_relative_selector()(the:has()argument list) callsparse_simple_selector()with no flag, so the result depends on the argument's position:The second XPath matches every
<a>that has any child element, so a selector that should be rejected matches far more than its author wrote. With the fix, each relative selector in:has()is parsed with a newinside_relative_selectorflag and:scoperaises the sameSelectorSyntaxErrorit already raises in:has(:scope)and:is(a, :scope). Other:has()arguments, and:scopeat the start of a top-level selector (a, :scope > b), are unchanged.