Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 197d671

Browse files
[DomCrawler] Deprecated using /_root/ in XPath expressions
1 parent c9e938c commit 197d671

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/Symfony/Component/DomCrawler/Crawler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,8 @@ private function relativize($xpath)
10361036

10371037
// BC for Symfony 2.4 and lower were elements were adding in a fake _root parent
10381038
if (0 === strpos($expression, '/_root/')) {
1039+
@trigger_error('XPath expressions referencing the fake root node are deprecated since version 2.8 and will be unsupported in 3.0. Please use "./" instead of "/_root/".', E_USER_DEPRECATED);
1040+
10391041
$expression = './'.substr($expression, 7);
10401042
} elseif (0 === strpos($expression, 'self::*/')) {
10411043
$expression = './'.substr($expression, 8);
@@ -1196,6 +1198,6 @@ private function triggerDeprecation($methodName, $useTrace = false)
11961198
return;
11971199
}
11981200

1199-
@trigger_error('The '.$methodName.' method is deprecated as of 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
1201+
@trigger_error('The '.$methodName.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
12001202
}
12011203
}

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,6 @@ public function testFilterXpathComplexQueries()
446446

447447
$this->assertCount(0, $crawler->filterXPath('/input'));
448448
$this->assertCount(0, $crawler->filterXPath('/body'));
449-
$this->assertCount(1, $crawler->filterXPath('/_root/body'));
450449
$this->assertCount(1, $crawler->filterXPath('./body'));
451450
$this->assertCount(1, $crawler->filterXPath('.//body'));
452451
$this->assertCount(5, $crawler->filterXPath('.//input'));
@@ -538,11 +537,20 @@ public function testFilterXPathWithFakeRoot()
538537
{
539538
$crawler = $this->createTestCrawler();
540539
$this->assertCount(0, $crawler->filterXPath('.'), '->filterXPath() returns an empty result if the XPath references the fake root node');
541-
$this->assertCount(0, $crawler->filterXPath('/_root'), '->filterXPath() returns an empty result if the XPath references the fake root node');
542540
$this->assertCount(0, $crawler->filterXPath('self::*'), '->filterXPath() returns an empty result if the XPath references the fake root node');
543541
$this->assertCount(0, $crawler->filterXPath('self::_root'), '->filterXPath() returns an empty result if the XPath references the fake root node');
544542
}
545543

544+
/** @group legacy */
545+
public function testLegacyFilterXPathWithFakeRoot()
546+
{
547+
$crawler = $this->createTestCrawler();
548+
$this->assertCount(0, $crawler->filterXPath('/_root'), '->filterXPath() returns an empty result if the XPath references the fake root node');
549+
550+
$crawler = $this->createTestCrawler()->filterXPath('//body');
551+
$this->assertCount(1, $crawler->filterXPath('/_root/body'));
552+
}
553+
546554
public function testFilterXPathWithAncestorAxis()
547555
{
548556
$crawler = $this->createTestCrawler()->filterXPath('//form');

0 commit comments

Comments
 (0)