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

Skip to content

[DomCrawler] Templates not excluded with DomCrawler #27285

Closed
@rrehbein

Description

@rrehbein

Symfony version(s) affected: 4.0.9

Description
DomCrawler does not exclude <template> tags when using forms

How to reproduce

// First, run "composer require symfony/dom-crawler"
<?php

require 'vendor/autoload.php';

use Symfony\Component\DomCrawler\Crawler;

$html = <<<'HTML'
<!DOCTYPE html>
<html>
    <body>
	<form>
		<template id="prototype">
			<input name="templated" value="Should be hidden">
		</template>
		<input name="static" value="Should be seen">
	</form>
    </body>
</html>
HTML;

$crawler = new Crawler($html, 'http://localhost/');

$form = $crawler->filterXPath('.//form')->form();

var_dump($form->getValues());

Actual output:

array(2) {
  ["templated"]=>
  string(16) "Should be hidden"
  ["static"]=>
  string(14) "Should be seen"
}

Expected output:

array(1) {
  ["static"]=>
  string(14) "Should be seen"
}

Possible Solution
Exclude template tags when identifying form fields.

Additional context
This was found while implementing a variation of the Form\Type\Collection with dynamic add, and it failed in WebTestCase.

<template> at this time is also not supported by IE

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions