10000 bug #10140 allow the TextAreaFormField to be used with valid/invalid … · symfony/symfony@545a218 · GitHub
[go: up one dir, main page]

Skip to content

Commit 545a218

Browse files
committed
bug #10140 allow the TextAreaFormField to be used with valid/invalid HTML (dawehner)
This PR was submitted for the 2.3-dev branch but it was merged into the 2.3 branch instead (closes #10140). Discussion ---------- allow the TextAreaFormField to be used with valid/invalid HTML The TextAreaFormField previously used saveXML to get a representation of the child nodes of an textarea. This works pretty fine on simple text is causes issues in case you have broken HTML, as saveXML will potentially also break encoding/change the structure. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT Commits ------- 157a9de allow the TextAreaFormField to be used with valid/invalid HTML
2 parents bacedea + 3db1b10 commit 545a218

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Symfony/Component/DomCrawler/Field/TextareaFormField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected function initialize()
3333

3434
$this->value = null;
3535
foreach ($this->node->childNodes as $node) {
36-
$this->value .= $this->document->saveXML($node);
36+
$this->value .= $node->wholeText;
3737
}
3838
}
3939
}

src/Symfony/Component/DomCrawler/Tests/Field/TextareaFormFieldTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,19 @@ public function testInitialize()
2929
} catch (\LogicException $e) {
3030
$this->assertTrue(true, '->initialize() throws a \LogicException if the node is not a textarea');
3131
}
32+
33+
// Ensure that valid HTML can be used on a textarea.
34+
$node = $this->createNode('textarea', 'foo bar <h1>Baz</h1>');
35+
$field = new TextareaFormField($node);
36+
37+
$this->assertEquals('foo bar <h1>Baz</h1>', $field->getValue(), '->initialize() sets the value of the field to the textarea node value');
38+
39+
// Ensure that we don't do any DOM manipulation/validation by passing in
40+
// "invalid" HTML.
41+
$node = $this->createNode('textarea', 'foo bar <h1>Baz</h2>');
42+
$field = new TextareaFormField($node);
43+
44+
$this->assertEquals('foo bar <h1>Baz</h2>', $field->getValue(), '->initialize() sets the value of the field to the textarea node value');
3245
}
46+
3347
}

0 commit comments

Comments
 (0)
0