Escaping value for FormHelper::textarea() and adding some tests, fixes #2921

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5778 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mariano.iglesias 2007-10-17 17:08:34 +00:00
parent ae3d082dd6
commit 1545b730ae
2 changed files with 20 additions and 1 deletions

View file

@ -836,9 +836,12 @@ class FormHelper extends AppHelper {
if (array_key_exists('value', $options)) {
$value = $options['value'];
if (!array_key_exists('escape', $options) || $options['escape'] !== false) {
$value = h($value);
}
unset($options['value']);
}
return $this->output(sprintf($this->Html->tags['textarea'], $options['name'], $this->_parseAttributes($options, array('type', 'name'), ' '), $value));
return $this->output(sprintf($this->Html->tags['textarea'], $options['name'], $this->_parseAttributes($options, array('type', 'name'), null, ' '), $value));
}
/**
* Creates a hidden input field.

View file

@ -512,6 +512,14 @@ class FormHelperTest extends CakeTestCase {
$expected = '<input name="data[Model][field]" type="text" id="theID" value="" />';
$this->assertEqual($result, $expected);
$this->Form->data['Model']['text'] = 'test <strong>HTML</strong> values';
$result = $this->Form->text('Model/text');
$this->assertPattern('/^<input[^<>]+type="text"[^<>]+\/>$/', $result);
$this->assertPattern('/^<input[^<>]+name="data\[Model\]\[text\]"[^<>]+\/>$/', $result);
$this->assertPattern('/^<input[^<>]+value="test &lt;strong&gt;HTML&lt;\/strong&gt; values"[^<>]+\/>$/', $result);
$this->assertNoPattern('/^<input[^<>]+name="[^<>]+name="[^<>]+\/>$/', $result);
$this->assertNoPattern('/<input[^<>]+[^type|name|id|value|class]=[^<>]*>/', $result);
$this->Form->validationErrors['Model']['text'] = 1;
$this->Form->data['Model']['text'] = 'test';
$result = $this->Form->text('Model/text', array('id' => 'theID'));
@ -876,6 +884,14 @@ class FormHelperTest extends CakeTestCase {
$result = $this->Form->textarea('Model/tmp');
$this->assertPattern('/^<textarea[^<>]+name="data\[Model\]\[tmp\]"[^<>]+><\/textarea>/', $result);
$this->Form->data = array('Model' => array('field' => 'some <strong>test</strong> data with <a href="#">HTML</a> chars'));
$result = $this->Form->textarea('Model.field');
$this->assertPattern('/^<textarea[^<>]+name="data\[Model\]\[field\]"[^<>]+id="ModelField"/', $result);
$this->assertPattern('/^<textarea[^<>]+>some &lt;strong&gt;test&lt;\/strong&gt; data with &lt;a href=&quot;#&quot;&gt;HTML&lt;\/a&gt; chars<\/textarea>$/', $result);
$this->assertNoPattern('/^<textarea[^<>]+value="[^<>]+>/', $result);
$this->assertNoPattern('/^<textarea[^<>]+name="[^<>]+name="[^<>]+>$/', $result);
$this->assertNoPattern('/<textarea[^<>]+[^name|id]=[^<>]*>/', $result);
}
function testHiddenField() {