From 72bd7762df6961f39cd8a18939cbc61b97b71a84 Mon Sep 17 00:00:00 2001 From: Eugenio Lacuesta Date: Fri, 23 Jul 2021 10:47:23 -0300 Subject: [PATCH] Revert xpath translation change to make it consistent --- cssselect/xpath.py | 4 +++- tests/test_cssselect.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cssselect/xpath.py b/cssselect/xpath.py index 13bc590..d7a2203 100644 --- a/cssselect/xpath.py +++ b/cssselect/xpath.py @@ -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): diff --git a/tests/test_cssselect.py b/tests/test_cssselect.py index e3e4761..5552b78 100644 --- a/tests/test_cssselect.py +++ b/tests/test_cssselect.py @@ -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")