Skip to content

Commit 157a9de

Browse files
committed
allow the TextAreaFormField to be used with valid/invalid HTML
1 parent 774674e commit 157a9de

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)