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 xpath translation change to make it consistent #1

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
4 changes: 3 additions & 1 deletion cssselect/xpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,9 @@ def xpath_relation_child_combinator(self, left, right):

def xpath_relation_direct_adjacent_combinator(self, left, right):
"""right is a sibling immediately after left; select left"""
xpath = left.add_condition("following-sibling::{}[position() = 1]".format(right.element))
xpath = left.add_condition(
"following-sibling::*[(name() = '{}') and (position() = 1)]".format(right.element)
)
return xpath

def xpath_relation_indirect_adjacent_combinator(self, left, right):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cssselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ def xpath(css):
assert xpath("e:has(~ f)") == "e[following-sibling::f]"
assert (
xpath("e:has(+ f)")
== "e[following-sibling::f[position() = 1]]"
== "e[following-sibling::*[(name() = 'f') and (position() = 1)]]"
)
assert xpath('e f') == (
"e/descendant-or-self::*/f")
Expand Down