Skip to content

Commit 78649a8

Browse files
committed
bug symfony#10987 [DomCrawler] Fixed a forgotten case of complex XPath queries (stof)
This PR was merged into the 2.3 branch. Discussion ---------- [DomCrawler] Fixed a forgotten case of complex XPath queries | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#10986 | License | MIT | Doc PR | n/a This fixes the case I forgot when rewritting the XPath to avoid making it produce invalid queries. I ran the new tests against the old implementation first, to ensure they cover the BC properly. I could have detected it by running the Mink 1.5 testsuite with the new code (which is the case for people reporting the bug), but I only ran it for Mink 1.6 which does not produce such XPath anymore. Commits ------- a9de61e [DomCrawler] Fixed a forgotten case of complex XPath queries
2 parents 29341fa + a9de61e commit 78649a8

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/Symfony/Component/DomCrawler/Crawler.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,8 @@ private function relativize($xpath)
839839
$expression = $nonMatchingExpression;
840840
} elseif (0 === strpos($expression, '//')) {
841841
$expression = 'descendant-or-self::' . substr($expression, 2);
842+
} elseif (0 === strpos($expression, './/')) {
843+
$expression = 'descendant-or-self::' . substr($expression, 3);
842844
} elseif (0 === strpos($expression, './')) {
843845
$expression = 'self::' . substr($expression, 2);
844846
} elseif ('/' === $expression[0]) {

src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ public function testFilterXpathComplexQueries()
376376
$this->assertCount(0, $crawler->filterXPath('/body'));
377377
$this->assertCount(1, $crawler->filterXPath('/_root/body'));
378378
$this->assertCount(1, $crawler->filterXPath('./body'));
379+
$this->assertCount(1, $crawler->filterXPath('.//body'));
380+
$this->assertCount(5, $crawler->filterXPath('.//input'));
379381
$this->assertCount(4, $crawler->filterXPath('//form')->filterXPath('//button | //input'));
380382
$this->assertCount(1, $crawler->filterXPath('body'));
381383
$this->assertCount(6, $crawler->filterXPath('//button | //input'));

0 commit comments

Comments
 (0)