Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert descendant combinator change #63

Merged
merged 1 commit into from
Oct 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cssselect/xpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def xpath_element(self, selector):

def xpath_descendant_combinator(self, left, right):
"""right is a child, grand-child or further descendant of left"""
return left.join('/descendant::', right)
return left.join('/descendant-or-self::*/', right)

def xpath_child_combinator(self, left, right):
"""right is an immediate child of left"""
Expand Down
10 changes: 5 additions & 5 deletions tests/test_cssselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ def xpath(css):
assert xpath('e:nth-last-of-type(1)') == (
"e[count(following-sibling::e) = 0]")
assert xpath('div e:nth-last-of-type(1) .aclass') == (
"div/descendant::e[count(following-sibling::e) = 0]"
"/descendant::*[@class and contains("
"div/descendant-or-self::*/e[count(following-sibling::e) = 0]"
"/descendant-or-self::*/*[@class and contains("
"concat(' ', normalize-space(@class), ' '), ' aclass ')]")

assert xpath('e:first-child') == (
Expand Down Expand Up @@ -423,7 +423,7 @@ def xpath(css):
assert xpath('e:nOT(*)') == (
"e[0]") # never matches
assert xpath('e f') == (
"e/descendant::f")
"e/descendant-or-self::*/f")
assert xpath('e > f') == (
"e/f")
assert xpath('e + f') == (
Expand All @@ -433,7 +433,7 @@ def xpath(css):
assert xpath('e ~ f:nth-child(3)') == (
"e/following-sibling::f[count(preceding-sibling::*) = 2]")
assert xpath('div#container p') == (
"div[@id = 'container']/descendant::p")
"div[@id = 'container']/descendant-or-self::*/p")

# Invalid characters in XPath element names
assert xpath(r'di\a0 v') == (
Expand Down Expand Up @@ -559,7 +559,7 @@ def xpath(css):
assert xpath('::text-node') == "descendant-or-self::*/text()"
assert xpath('::attr-href') == "descendant-or-self::*/@href"
assert xpath('p img::attr(src)') == (
"descendant-or-self::p/descendant::img/@src")
"descendant-or-self::p/descendant-or-self::*/img/@src")

def test_series(self):
def series(css):
Expand Down