Skip to content

Commit

Permalink
Merge pull request #95 from Gallaecio/fix-scope-not-first
Browse files Browse the repository at this point in the history
Support :scope after a comma delimiter
  • Loading branch information
wRAR committed Oct 24, 2022
2 parents 1514eff + aa4ff01 commit 5c2719d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cssselect/parser.py
Expand Up @@ -625,6 +625,12 @@ def parse_simple_selector(stream, inside_negation=False):
if not (
len(stream.used) == 2
or (len(stream.used) == 3 and stream.used[0].type == "S")
or (len(stream.used) >= 3 and stream.used[-3].is_delim(","))
or (
len(stream.used) >= 4
and stream.used[-3].type == "S"
and stream.used[-4].is_delim(",")
)
):
raise SelectorSyntaxError(
'Got immediate child pseudo-element ":scope" '
Expand Down
8 changes: 8 additions & 0 deletions tests/test_cssselect.py
Expand Up @@ -230,6 +230,14 @@ def test_pseudo_repr(css):
("CombinedSelector[Pseudo[Element[*]:scope] > Element[div]]", None),
("CombinedSelector[Element[foo] <followed> Element[bar]]", None),
]
assert parse_pseudo("foo bar, :scope > div") == [
("CombinedSelector[Element[foo] <followed> Element[bar]]", None),
("CombinedSelector[Pseudo[Element[*]:scope] > Element[div]]", None),
]
assert parse_pseudo("foo bar,:scope > div") == [
("CombinedSelector[Element[foo] <followed> Element[bar]]", None),
("CombinedSelector[Pseudo[Element[*]:scope] > Element[div]]", None),
]
assert parse_pseudo("foo:before, bar, baz:after") == [
("Element[foo]", "before"),
("Element[bar]", None),
Expand Down

0 comments on commit 5c2719d

Please sign in to comment.