Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Making optiongroup elements follow the escape parameter.

Tests added.
Fixes #1191
  • Loading branch information...
commit 6529e0e2b4ef45de939a39bbe923dada6dcea869 1 parent 3f2109f
@markstory markstory authored
View
1  cake/libs/view/helpers/form.php
@@ -2002,6 +2002,7 @@ function __selectOptions($elements = array(), $selected = null, $parents = array
));
if (!empty($name)) {
+ $name = $attributes['escape'] ? h($name) : $name;
if ($attributes['style'] === 'checkbox') {
$select[] = sprintf($this->Html->tags['fieldsetstart'], $name);
} else {
View
41 cake/tests/cases/libs/view/helpers/form.test.php
@@ -3116,6 +3116,47 @@ function testSelect() {
}
/**
+ * test that select() with optiongroups listens to the escape param.
+ *
+ * @return void
+ */
+ function testSelectOptionGroupEscaping() {
+ $options = array(
+ '>< Key' => array(
+ 1 => 'One',
+ 2 => 'Two'
+ )
+ );
+ $result = $this->Form->select('Model.field', $options, null, array('empty' => false));
+ $expected = array(
+ 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
+ 'optgroup' => array('label' => '&gt;&lt; Key'),
+ array('option' => array('value' => '1')), 'One', '/option',
+ array('option' => array('value' => '2')), 'Two', '/option',
+ '/optgroup',
+ '/select'
+ );
+ $this->assertTags($result, $expected);
+
+ $options = array(
+ '>< Key' => array(
+ 1 => 'One',
+ 2 => 'Two'
+ )
+ );
+ $result = $this->Form->select('Model.field', $options, null, array('empty' => false, 'escape' => false));
+ $expected = array(
+ 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'),
+ 'optgroup' => array('label' => '>< Key'),
+ array('option' => array('value' => '1')), 'One', '/option',
+ array('option' => array('value' => '2')), 'Two', '/option',
+ '/optgroup',
+ '/select'
+ );
+ $this->assertTags($result, $expected);
+ }
+
+/**
* Tests that FormHelper::select() allows null to be passed in the $attributes parameter
*
* @access public
Please sign in to comment.
Something went wrong with that request. Please try again.