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 19cc7b0

Browse filesBrowse files
Merge branch '6.4' into 7.2
* 6.4: fix integration tests Check for null parent Nodes in the case of orphaned branches
2 parents 700a880 + 19073e3 commit 19cc7b0
Copy full SHA for 19cc7b0

File tree

Expand file treeCollapse file tree

2 files changed

+24
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+24
-1
lines changed

‎Crawler.php

Copy file name to clipboardExpand all lines: Crawler.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ public function closest(string $selector): ?self
411411

412412
$domNode = $this->getNode(0);
413413

414-
while (\XML_ELEMENT_NODE === $domNode->nodeType) {
414+
while (null !== $domNode && \XML_ELEMENT_NODE === $domNode->nodeType) {
415415
$node = $this->createSubCrawler($domNode);
416416
if ($node->matches($selector)) {
417417
return $node;

‎Tests/AbstractCrawlerTestCase.php

Copy file name to clipboardExpand all lines: Tests/AbstractCrawlerTestCase.php
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,29 @@ public function testClosest()
10311031
$this->assertNull($notFound);
10321032
}
10331033

1034+
public function testClosestWithOrphanedNode()
1035+
{
1036+
$html = <<<'HTML'
1037+
<html lang="en">
1038+
<body>
1039+
<div id="foo" class="newFoo ok">
1040+
<div class="lorem1 ko"></div>
1041+
</div>
1042+
</body>
1043+
</html>
1044+
HTML;
1045+
1046+
$crawler = $this->createCrawler($this->getDoctype().$html);
1047+
$foo = $crawler->filter('#foo');
1048+
1049+
$fooNode = $foo->getNode(0);
1050+
1051+
$fooNode->parentNode->replaceChild($fooNode->ownerDocument->createElement('ol'), $fooNode);
1052+
1053+
$body = $foo->closest('body');
1054+
$this->assertNull($body);
1055+
}
1056+
10341057
public function testOuterHtml()
10351058
{
10361059
$html = <<<'HTML'

0 commit comments

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