Skip to content

Commit

Permalink
Fix issue that prevents using a leading combinator :has() selector (#83)
Browse files Browse the repository at this point in the history
Fix issue with `:has()` selector where a leading combinator can only be
provided in the first selector in a relative selector list.
  • Loading branch information
facelessuser authored Jan 12, 2019
1 parent 14c1018 commit 5639b5e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
5 changes: 5 additions & 0 deletions docs/src/markdown/about/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.7.1

- **FIX**: Fix issue with `:has()` selector where a leading combinator can only be provided in the first selector in a
relative selector list.

## 1.7.0

- **NEW**: Add support for `:in-range` and `:out-of-range` selectors. (#60)
Expand Down
2 changes: 1 addition & 1 deletion soupsieve/__meta__.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,5 @@ def parse_version(ver, pre=False):
return Version(major, minor, micro, release, pre, post, dev)


__version_info__ = Version(1, 7, 0, "final")
__version_info__ = Version(1, 7, 1, "final")
__version__ = __version_info__._get_canonical()
2 changes: 0 additions & 2 deletions soupsieve/css_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,6 @@ def parse_selectors(self, iselector, index=0, flags=0):
else:
raise SyntaxError("Unmatched pseudo-class close at postion {}".format(m.start(0)))
elif key == 'combine':
if split_last:
raise SyntaxError("Unexpected combinator at position {}".format(m.start(0)))
if is_relative:
has_selector, sel, rel_type = self.parse_has_combinator(
sel, m, has_selector, selectors, rel_type, index
Expand Down
7 changes: 7 additions & 0 deletions tests/test_level4.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@ def test_has(self):
flags=util.HTML5
)

self.assert_selector(
markup2,
'div:has(.ffff, > .bbbb, .jjjj)',
['0', '4', '8'],
flags=util.HTML5
)

self.assert_selector(
markup2,
'div:has(> :not(.bbbb, .ffff, .jjjj))',
Expand Down
18 changes: 18 additions & 0 deletions tests/test_soupsieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,12 @@ def test_invalid_combination(self):
with self.assertRaises(SyntaxError):
sv.compile('div >')

with self.assertRaises(SyntaxError):
sv.compile('div, > a')

with self.assertRaises(SyntaxError):
sv.compile('div,, a')

def test_invalid_pseudo(self):
"""Test invalid pseudo class."""

Expand Down Expand Up @@ -330,6 +336,18 @@ def test_invalid_incomplete_has(self):
with self.assertRaises(SyntaxError):
sv.compile(':has()')

with self.assertRaises(SyntaxError):
sv.compile(':has(> has,, a)')

with self.assertRaises(SyntaxError):
sv.compile(':has(> has,, a)')

with self.assertRaises(SyntaxError):
sv.compile(':has(> has >)')

with self.assertRaises(SyntaxError):
sv.compile(':has(> has,)')

def test_invalid_tag(self):
"""
Test invalid tag.
Expand Down

0 comments on commit 5639b5e

Please sign in to comment.