diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 9b95737b4..ffef2953c 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -751,6 +751,13 @@ class FormHelper extends AppHelper { */ function select($fieldName, $options = array(), $selected = null, $attributes = array(), $showEmpty = '') { $showParents = false; + $escapeOptions = true; + + if (isset($attributes['escape'])) { + $escapeOptions = $attributes['escape']; + unset($attributes['escape']); + } + $this->setFormTag($fieldName); $this->__secure(); $attributes = $this->domId((array)$attributes); @@ -790,7 +797,7 @@ class FormHelper extends AppHelper { $options[''] = $showEmpty; $options = array_reverse($options, true); } - $select = am($select, $this->__selectOptions(array_reverse($options, true), $selected, array(), $showParents)); + $select = am($select, $this->__selectOptions(array_reverse($options, true), $selected, array(), $showParents, array('escape' => $escapeOptions))); $select[] = sprintf($this->Html->tags['selectend']); return $this->output(implode("\n", $select)); } @@ -1033,7 +1040,9 @@ class FormHelper extends AppHelper { * * @return array */ - function __selectOptions($elements = array(), $selected = null, $parents = array(), $showParents = null) { + function __selectOptions($elements = array(), $selected = null, $parents = array(), $showParents = null, $attributes = array()) { + $attributes = am(array('escape' => true), $attributes); + $select = array(); foreach($elements as $name => $title) { $htmlOptions = array(); @@ -1042,7 +1051,7 @@ class FormHelper extends AppHelper { $select[] = $this->Html->tags['optiongroupend']; $parents[] = $name; } - $select = am($select, $this->__selectOptions($title, $selected, $parents, $showParents)); + $select = am($select, $this->__selectOptions($title, $selected, $parents, $showParents, $attributes)); if (!empty($name)) { $select[] = sprintf($this->Html->tags['optiongroup'], $name, ''); } @@ -1061,7 +1070,8 @@ class FormHelper extends AppHelper { } if($showParents || (!in_array($title, $parents))) { - $select[] = sprintf($this->Html->tags['selectoption'], $name, $this->Html->_parseAttributes($htmlOptions), h($title)); + $title = ife($attributes['escape'], h($title), $title); + $select[] = sprintf($this->Html->tags['selectoption'], $name, $this->Html->_parseAttributes($htmlOptions), $title); } } } diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index fa967fe9d..9a9a98209 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -537,6 +537,32 @@ class FormHelperTest extends CakeTestCase { $this->assertNoPattern('/option value="other"\s+selected="selected"/', $result); $this->assertNoPattern('/]+[^name|id]=[^<>]*>/', $result); $this->assertNoPattern('/]+[^value|selected]=[^<>]*>/', $result); + + $this->Form->data = array(); + $result = $this->Form->select('Model/field', array('value' => 'good', 'other' => 'bad')); + $this->assertPattern('/option value=""/', $result); + $this->assertPattern('/option value="value"/', $result); + $this->assertPattern('/option value="other"/', $result); + $this->assertPattern('/<\/option>\s+