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 838dc7e

Browse filesBrowse files
committed
Merge branch '2.4'
* 2.4: Revert "bug #10207 [DomCrawler] Fixed filterXPath() chaining (robbertkl)" Bypass sigchild detection if phpinfo is not available
2 parents 5a5eb50 + 88118a2 commit 838dc7e
Copy full SHA for 838dc7e

File tree

Expand file treeCollapse file tree

5 files changed

+39
-21
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+39
-21
lines changed

‎src/Symfony/Component/DomCrawler/Crawler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DomCrawler/Crawler.php
+8-6Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ public function parents()
454454
$nodes = array();
455455

456456
while ($node = $node->parentNode) {
457-
if (1 === $node->nodeType) {
457+
if (1 === $node->nodeType && '_root' !== $node->nodeName) {
458458
$nodes[] = $node;
459459
}
460460
}
@@ -599,14 +599,16 @@ public function extract($attributes)
599599
*/
600600
public function filterXPath($xpath)
601601
{
602-
$crawler = new static(null, $this->uri);
603-
$prefixes = $this->findNamespacePrefixes($xpath);
602+
$document = new \DOMDocument('1.0', 'UTF-8');
603+
$root = $document->appendChild($document->createElement('_root'));
604604
foreach ($this as $node) {
605-
$domxpath = $this->createDOMXPath($node->ownerDocument, $prefixes);
606-
$crawler->add($domxpath->query($xpath, $node));
605+
$root->appendChild($document->importNode($node, true));
607606
}
608607

609-
return $crawler;
608+
$prefixes = $this->findNamespacePrefixes($xpath);
609+
$domxpath = $this->createDOMXPath($document, $prefixes);
610+
611+
return new static($domxpath->query($xpath), $this->uri);
610612
}
611613

612614
/**

‎src/Symfony/Component/DomCrawler/Field/FormField.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DomCrawler/Field/FormField.php
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ public function __construct(\DOMNode $node)
5252
{
5353
$this->node = $node;
5454
$this->name = $node->getAttribute('name');
55-
$this->xpath = new \DOMXPath($node->ownerDocument);
55+
56+
$this->document = new \DOMDocument('1.0', 'UTF-8');
57+
$this->node = $this->document->importNode($this->node, true);
58+
59+
$root = $this->document->appendChild($this->document->createElement('_root'));
60+
$root->appendChild($this->node);
61+
$this->xpath = new \DOMXPath($this->document);
5662

5763
$this->initialize();
5864
}

‎src/Symfony/Component/DomCrawler/Form.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DomCrawler/Form.php
+19-11Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,9 @@ private function initialize()
394394
{
395395
$this->fields = new FormFieldRegistry();
396396

397-
$xpath = new \DOMXPath($this->node->ownerDocument);
397+
$document = new \DOMDocument('1.0', 'UTF-8');
398+
$xpath = new \DOMXPath($document);
399+
$root = $document->appendChild($document->createElement('_root'));
398400

399401
// add submitted button if it has a valid name
400402
if ('form' !== $this->button->nodeName && $this->button->hasAttribute('name') && $this->button->getAttribute('name')) {
@@ -404,33 +406,39 @@ private function initialize()
404406

405407
// temporarily change the name of the input node for the x coordinate
406408
$this->button->setAttribute('name', $name.'.x');
407-
$this->set(new Field\InputFormField($this->button));
409+
$this->set(new Field\InputFormField($document->importNode($this->button, true)));
408410

409411
// temporarily change the name of the input node for the y coordinate
410412
$this->button->setAttribute('name', $name.'.y');
411-
$this->set(new Field\InputFormField($this->button));
413+
$this->set(new Field\InputFormField($document->importNode($this->button, true)));
412414

413415
// restore the original name of the input node
414416
$this->button->setAttribute('name', $name);
415-
} else {
416-
$this->set(new Field\InputFormField($this->button));
417+
}
418+
else {
419+
$this->set(new Field\InputFormField($document->importNode($this->button, true)));
417420
}
418421
}
419422

420423
// find form elements corresponding to the current form
421424
if ($this->node->hasAttribute('id')) {
425+
// traverse through the whole document
426+
$node = $document->importNode($this->node->ownerDocument->documentElement, true);
427+
$root->appendChild($node);
428+
422429
// corresponding elements are either descendants or have a matching HTML5 form attribute
423430
$formId = Crawler::xpathLiteral($this->node->getAttribute('id'));
424-
425-
// do the xpath query without $this->node as the context node (i.e. traverse through the whole document)
426-
$fieldNodes = $xpath->query(sprintf('descendant::input[@form=%s] | descendant::button[@form=%s] | descendant::textarea[@form=%s] | descendant::select[@form=%s] | //form[@id=%s]//input[not(@form)] | //form[@id=%s]//button[not(@form)] | //form[@id=%s]//textarea[not(@form)] | //form[@id=%s]//select[not(@form)]', $formId, $formId, $formId, $formId, $formId, $formId, $formId, $formId));
431+
$fieldNodes = $xpath->query(sprintf('descendant::input[@form=%s] | descendant::button[@form=%s] | descendant::textarea[@form=%s] | descendant::select[@form=%s] | //form[@id=%s]//input[not(@form)] | //form[@id=%s]//button[not(@form)] | //form[@id=%s]//textarea[not(@form)] | //form[@id=%s]//select[not(@form)]', $formId, $formId, $formId, $formId, $formId, $formId, $formId, $formId), $root);
427432
foreach ($fieldNodes as $node) {
428433
$this->addField($node);
429434
}
430435
} else {
431-
// do the xpath query with $this->node as the context node, to only find descendant elements
432-
// however, descendant elements with form attribute are not part of this form
433-
$fieldNodes = $xpath->query('descendant::input[not(@form)] | descendant::button[not(@form)] | descendant::textarea[not(@form)] | descendant::select[not(@form)]', $this->node);
436+
// parent form has no id, add descendant elements only
437+
$node = $document->importNode($this->node, true);
438+
$root->appendChild($node);
439+
440+
// descendant elements with form attribute are not part of this form
441+
$fieldNodes = $xpath->query('descendant::input[not(@form)] | descendant::button[not(@form)] | descendant::textarea[not(@form)] | descendant::select[not(@form)]', $root);
434442
foreach ($fieldNodes as $node) {
435443
$this->addField($node);
436444
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,8 @@ public function testFilterXPath()
390390
$this->assertInstanceOf('Symfony\\Component\\DomCrawler\\Crawler', $crawler, '->filterXPath() returns a new instance of a crawler');
391391

392392
$crawler = $this->createTestCrawler()->filterXPath('//ul');
393-
$this->assertCount(6, $crawler->filterXPath('//li'), '->filterXPath() filters the node list with the XPath expression');
394393

395-
$crawler = $this->createTestCrawler();
396-
$this->assertCount(3, $crawler->filterXPath('//body')->filterXPath('//button')->parents(), '->filterXpath() preserves parents when chained');
394+
$this->assertCount(6, $crawler->filterXPath('//li'), '->filterXPath() filters the node list with the XPath expression');
397395
}
398396

399397
public function testFilterXPathWithDefaultNamespace()

‎src/Symfony/Component/Process/Process.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/Process.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,10 @@ protected function isSigchildEnabled()
11561156
return self::$sigchild;
11571157
}
11581158

1159+
if (!function_exists('phpinfo')) {
1160+
return self::$sigchild = false;
1161+
}
1162+
11591163
ob_start();
11601164
phpinfo(INFO_GENERAL);
11611165

0 commit comments

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