8000 [CssSelector] For AND operator, the left operand should have parenthe… · symfony/symfony@28c42a0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 28c42a0

Browse files
Arnaud CHASSEUXnicolas-grekas
Arnaud CHASSEUX
authored andcommitted
[CssSelector] For AND operator, the left operand should have parentheses, not only right operand
1 parent b9bb577 commit 28c42a0

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

src/Symfony/Component/CssSelector/Tests/CssSelectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function getCssToXPathWithoutPrefixTestData()
4848
array('h1', 'h1'),
4949
array('foo|h1', 'foo:h1'),
5050
array('h1, h2, h3', 'h1 | h2 | h3'),
51-
array('h1:nth-child(3n+1)', "*/*[name() = 'h1' and (position() - 1 >= 0 and (position() - 1) mod 3 = 0)]"),
51+
array('h1:nth-child(3n+1)', "*/*[(name() = 'h1') and (position() - 1 >= 0 and (position() - 1) mod 3 = 0)]"),
5252
array('h1 > p', 'h1/p'),
5353
array('h1#foo', "h1[@id = 'foo']"),
5454
array('h1.foo', "h1[@class and contains(concat(' ', normalize-space(@class), ' '), ' foo ')]"),

src/Symfony/Component/CssSelector/Tests/XPath/TranslatorTest.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,20 @@ public function getCssToXPathTestData()
102102
array('e[foo^="bar"]', "e[@foo and starts-with(@foo, 'bar')]"),
103103
array('e[foo$="bar"]', "e[@foo and substring(@foo, string-length(@foo)-2) = 'bar']"),
104104
array('e[foo*="bar"]', "e[@foo and contains(@foo, 'bar')]"),
105+
array('e[foo!="bar"]', "e[not(@foo) or @foo != 'bar']"),
106+
array('e[foo!="bar"][foo!="baz"]', "e[(not(@foo) or @foo != 'bar') and (not(@foo) or @foo != 'baz')]"),
105107
array('e[hreflang|="en"]', "e[@hreflang and (@hreflang = 'en' or starts-with(@hreflang, 'en-'))]"),
106-
array('e:nth-child(1)', "*/*[name() = 'e' and (position() = 1)]"),
107-
array('e:nth-last-child(1)', "*/*[name() = 'e' and (position() = last() - 0)]"),
108-
array('e:nth-last-child(2n+2)', "*/*[name() = 'e' and (last() - position() - 1 >= 0 and (last() - position() - 1) mod 2 = 0)]"),
108+
array('e:nth-child(1)', "*/*[(name() = 'e') and (position() = 1)]"),
109+
array('e:nth-last-child(1)', "*/*[(name() = 'e') and (position() = last() - 0)]"),
110+
array('e:nth-last-child(2n+2)', "*/*[(name() = 'e') and (last() - position() - 1 >= 0 and (last() - position() - 1) mod 2 = 0)]"),
109111
array('e:nth-of-type(1)', '*/e[position() = 1]'),
110112
array('e:nth-last-of-type(1)', '*/e[position() = last() - 0]'),
111113
array('div e:nth-last-of-type(1) .aclass', "div/descendant-or-self::*/e[position() = last() - 0]/descendant-or-self::*/*[@class and contains(concat(' ', normalize-space(@class), ' '), ' aclass ')]"),
112-
array('e:first-child', "*/*[name() = 'e' and (position() = 1)]"),
113-
array('e:last-child', "*/*[name() = 'e' and (position() = last())]"),
114+
array('e:first-child', "*/*[(name() = 'e') and (position() = 1)]"),
115+
array('e:last-child', "*/*[(name() = 'e') and (position() = last())]"),
114116
array('e:first-of-type', '*/e[position() = 1]'),
115117
array('e:last-of-type', '*/e[position() = last()]'),
116-
array('e:only-child', "*/*[name() = 'e' and (last() = 1)]"),
118+
array('e:only-child', "*/*[(name() = 'e') and (last() = 1)]"),
117119
array('e:only-of-type', 'e[last() = 1]'),
118120
array('e:empty', 'e[not(*) and not(string-length())]'),
119121
array('e:EmPTY', 'e[not(*) and not(string-length())]'),
@@ -127,7 +129,7 @@ public function getCssToXPathTestData()
127129
array('e:nOT(*)', 'e[0]'),
128130
array('e f', 'e/descendant-or-self::*/f'),
129131
array('e > f', 'e/f'),
130-
array('e + f', "e/following-sibling::*[name() = 'f' and (position() = 1)]"),
132+
array('e + f', "e/following-sibling::*[(name() = 'f') and (position() = 1)]"),
131133
array('e ~ f', 'e/following-sibling::f'),
132134
array('div#container p', "div[@id = 'container']/descendant-or-self::*/p"),
133135
);

src/Symfony/Component/CssSelector/XPath/XPathExpr.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function getElement()
5757
*/
5858
public function addCondition($condition)
5959
{
60-
$this->condition = $this->condition ? sprintf('%s and (%s)', $this->condition, $condition) : $condition;
60+
$this->condition = $this->condition ? sprintf('(%s) and (%s)', $this->condition, $condition) : $condition;
6161

6262
return $this;
6363
}

0 commit comments

Comments
 (0)
0