Skip to content

Commit 7438a32

Browse files
Merge branch '4.1'
* 4.1: (23 commits) [Routing] fix trailing slash redirection when using RedirectableUrlMatcher [PropertyAccessor] fix encoding of cache keys [WebProfiler] Detect empty file paths in file viewer fixed CS Changes for upcoming Travis' infra migration Doc fix: clarify isMethodCacheable() returns true only for GET & HEAD [MonologBridge] Return empty list for unknonwn requests [DomCrawler] exclude fields inside "template" tags Use XLIFF source rather than resname when there's no target [DoctrineBridge] catch errors while converting to db values in data collector [DoctrineBridge] fix case sensitivity issue in RememberMe\DoctrineTokenProvider [EventDispatcher] Unwrap wrapped listeners internally [Routing] fix trailing slash redirection when using RedirectableUrlMatcher Removed the return type phpdoc fix authorization checker variable name [Routing] Remove duplicate schemes and methods for invokable controllers Indentation error [HttpFoundation] Fix trailing space for mime-type with parameters [HttpFoundation] Fixed absolute Request URI with default port [Bridge/PhpUnit] fix the fix ...
2 parents 3d17eab + a9f5335 commit 7438a32

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Form.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,14 +443,14 @@ private function initialize()
443443
// corresponding elements are either descendants or have a matching HTML5 form attribute
444444
$formId = Crawler::xpathLiteral($this->node->getAttribute('id'));
445445

446-
$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));
446+
$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));
447447
foreach ($fieldNodes as $node) {
448448
$this->addField($node);
449449
}
450450
} else {
451451
// do the xpath query with $this->node as the context node, to only find descendant elements
452452
// however, descendant elements with form attribute are not part of this form
453-
$fieldNodes = $xpath->query('descendant::input[not(@form)] | descendant::button[not(@form)] | descendant::textarea[not(@form)] | descendant::select[not(@form)]', $this->node);
453+
$fieldNodes = $xpath->query('( descendant::input[not(@form)] | descendant::button[not(@form)] | descendant::textarea[not(@form)] | descendant::select[not(@form)] )[not(ancestor::template)]', $this->node);
454454
foreach ($fieldNodes as $node) {
455455
$this->addField($node);
456456
}

Tests/FormTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,10 @@ public function testGetValues()
400400

401401
$form = $this->createForm('<form><input type="text" name="foo" value="foo" disabled="disabled" /><input type="text" name="bar" value="bar" /><input type="submit" /></form>');
402402
$this->assertEquals(array('bar' => 'bar'), $form->getValues(), '->getValues() does not include disabled fields');
403+
404+
$form = $this->createForm('<form><template><input type="text" name="foo" value="foo" /></template><input type="text" name="bar" value="bar" /><input type="submit" /></form>');
405+
$this->assertEquals(array('bar' => 'bar'), $form->getValues(), '->getValues() does not include template fields');
406+
$this->assertFalse($form->has('foo'));
403407
}
404408

405409
public function testSetValues()
@@ -450,6 +454,10 @@ public function testGetFiles()
450454

451455
$form = $this->createForm('<form method="post"><input type="file" name="foo[bar]" disabled="disabled" /><input type="submit" /></form>');
452456
$this->assertEquals(array(), $form->getFiles(), '->getFiles() does not include disabled file fields');
457+
458+
$form = $this->createForm('<form method="post"><template><input type="file" name="foo"/></template><input type="text" name="bar" value="bar"/><input type="submit"/></form>');
459+
$this->assertEquals(array(), $form->getFiles(), '->getFiles() does not include template file fields');
460+
$this->assertFalse($form->has('foo'));
453461
}
454462

455463
public function testGetPhpFiles()
@@ -869,7 +877,7 @@ protected function getFormFieldMock($name, $value = null)
869877
protected function createForm($form, $method = null, $currentUri = null)
870878
{
871879
$dom = new \DOMDocument();
872-
$dom->loadHTML('<html>'.$form.'</html>');
880+
@$dom->loadHTML('<html>'.$form.'</html>');
873881

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

0 commit comments

Comments
 (0)