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
This commit is contained in:
Fabien Potencier 2014-01-26 22:32:17 +01:00
commit 545a21870e
2 changed files with 15 additions and 1 deletions

View File

@ -33,7 +33,7 @@ class TextareaFormField extends FormField
$this->value = null;
foreach ($this->node->childNodes as $node) {
$this->value .= $this->document->saveXML($node);
$this->value .= $node->wholeText;
}
}
}

View File

@ -29,5 +29,19 @@ class TextareaFormFieldTest extends FormFieldTestCase
} catch (\LogicException $e) {
$this->assertTrue(true, '->initialize() throws a \LogicException if the node is not a textarea');
}
// Ensure that valid HTML can be used on a textarea.
$node = $this->createNode('textarea', 'foo bar <h1>Baz</h1>');
$field = new TextareaFormField($node);
$this->assertEquals('foo bar <h1>Baz</h1>', $field->getValue(), '->initialize() sets the value of the field to the textarea node value');
// Ensure that we don't do any DOM manipulation/validation by passing in
// "invalid" HTML.
$node = $this->createNode('textarea', 'foo bar <h1>Baz</h2>');
$field = new TextareaFormField($node);
$this->assertEquals('foo bar <h1>Baz</h2>', $field->getValue(), '->initialize() sets the value of the field to the textarea node value');
}
}