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

Browse filesBrowse files
Sergei Gorjunovnicolas-grekas
Sergei Gorjunov
authored andcommitted
[DomCrawler] exclude fields inside "template" tags
1 parent e4a7fd8 commit 19e3e15
Copy full SHA for 19e3e15

File tree

Expand file treeCollapse file tree

2 files changed

+11
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+11
-3
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DomCrawler/Form.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,14 +433,14 @@ private function initialize()
433433
// corresponding elements are either descendants or have a matching HTML5 form attribute
434434
$formId = Crawler::xpathLiteral($this->node->getAttribute('id'));
435435

436-
$fieldNodes = $xpath->query(sprintf('descendant::input[@form=%s] | descendant::button[@form=%1$s] | descendant::textarea[@form=%1$s] | descendant::select[@form=%1$s] | //form[@id=%1$s]//input[not(@form)] | //form[@id=%1$s]//button[not(@form)] | //form[@id=%1$s]//textarea[not(@form)] | //form[@id=%1$s]//select[not(@form)]', $formId));
436+
$fieldNodes = $xpath->query(sprintf('( descendant::input[@form=%s] | descendant::button[@form=%1$s] | descendant::textarea[@form=%1$s] | descendant::select[@form=%1$s] | //form[@id=%1$s]//input[not(@form)] | //form[@id=%1$s]//button[not(@form)] | //form[@id=%1$s]//textarea[not(@form)] | //form[@id=%1$s]//select[not(@form)] )[not(ancestor::template)]', $formId));
437437
foreach ($fieldNodes as $node) {
438438
$this->addField($node);
439439
}
440440
} else {
441441
// do the xpath query with $this->node as the context node, to only find descendant elements
442442
// however, descendant elements with form attribute are not part of this form
443-
$fieldNodes = $xpath->query('descendant::input[not(@form)] | descendant::button[not(@form)] | descendant::textarea[not(@form)] | descendant::select[not(@form)]', $this->node);
443+
$fieldNodes = $xpath->query('( descendant::input[not(@form)] | descendant::button[not(@form)] | descendant::textarea[not(@form)] | descendant::select[not(@form)] )[not(ancestor::template)]', $this->node);
444444
foreach ($fieldNodes as $node) {
445445
$this->addField($node);
446446
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DomCrawler/Tests/FormTest.php
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@ public function testGetValues()
394394

395395
$form = $this->createForm('<form><input type="text" name="foo" value="foo" disabled="disabled" /><input type="text" name="bar" value="bar" /><input type="submit" /></form>');
396396
$this->assertEquals(array('bar' => 'bar'), $form->getValues(), '->getValues() does not include disabled fields');
397+
398+
$form = $this->createForm('<form><template><input type="text" name="foo" value="foo" /></template><input type="text" name="bar" value="bar" /><input type="submit" /></form>');
399+
$this->assertEquals(array('bar' => 'bar'), $form->getValues(), '->getValues() does not include template fields');
400+
$this->assertFalse($form->has('foo'));
397401
}
398402

399403
public function testSetValues()
@@ -444,6 +448,10 @@ public function testGetFiles()
444448

445449
$form = $this->createForm('<form method="post"><input type="file" name="foo[bar]" disabled="disabled" /><input type="submit" /></form>');
446450
$this->assertEquals(array(), $form->getFiles(), '->getFiles() does not include disabled file fields');
451+
452+
$form = $this->createForm('<form method="post"><template><input type="file" name="foo"/></template><input type="text" name="bar" value="bar"/><input type="submit"/></form>');
453+
$this->assertEquals(array(), $form->getFiles(), '->getFiles() does not include template file fields');
454+
$this->assertFalse($form->has('foo'));
447455
}
448456

449457
public function testGetPhpFiles()
@@ -857,7 +865,7 @@ protected function getFormFieldMock($name, $value = null)
857865
protected function createForm($form, $method = null, $currentUri = null)
858866
{
859867
$dom = new \DOMDocument();
860-
$dom->loadHTML('<html>'.$form.'</html>');
868+
@$dom->loadHTML('<html>'.$form.'</html>');
861869

862870
$xPath = new \DOMXPath($dom);
863871
$nodes = $xPath->query('//input | //button');

0 commit comments

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