Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1111da7

Browse filesBrowse files
bug #26010 [CssSelector] For AND operator, the left operand should have parentheses, not only right operand (Arnaud CHASSEUX)
This PR was merged into the 2.7 branch. Discussion ---------- [CssSelector] For AND operator, the left operand should have parentheses, not only right operand | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - From symfony/css-selector#3 Commits ------- 76b40dc [CssSelector] For AND operator, the left operand should have parentheses, not only right operand
2 parents d0e03a4 + 76b40dc commit 1111da7
Copy full SHA for 1111da7

File tree

Expand file treeCollapse file tree

3 files changed

+12
-10
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+12
-10
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/CssSelector/Tests/CssSelectorTest.php
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/CssSelector/Tests/XPath/TranslatorTest.php
+9-7Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/CssSelector/XPath/XPathExpr.php
+2-2Lines changed: 2 additions & 2 deletions
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
}
@@ -101,7 +101,7 @@ public function addStarPrefix()
101101
*
102102
* @return $this
103103
*/
104-
public function join($combiner, XPathExpr $expr)
104+
public function join($combiner, self $expr)
105105
{
106106
$path = $this->__toString().$combiner;
107107

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.