From 6529e0e2b4ef45de939a39bbe923dada6dcea869 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 13 Oct 2010 21:59:53 -0400 Subject: [PATCH] Making optiongroup elements follow the escape parameter. Tests added. Fixes #1191 --- cake/libs/view/helpers/form.php | 1 + .../cases/libs/view/helpers/form.test.php | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 319215190c4..72ffcd8c00f 100644 --- a/cake/libs/view/helpers/form.php +++ b/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 { diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index e30e2a20542..9a824334d1a 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -3115,6 +3115,47 @@ function testSelect() { $this->assertTags($result, $expected); } +/** + * 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' => '>< 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 *