From 3978f87c581357d8ee8ef088810aace2ffcefa0e Mon Sep 17 00:00:00 2001 From: kanonji Date: Tue, 28 Feb 2017 00:16:53 +0900 Subject: [PATCH] Stringify values to avoid trap of in_array() type juggling --- .../Test/Case/View/Helper/FormHelperTest.php | 54 +++++++++++++++++++ lib/Cake/View/Helper/FormHelper.php | 2 +- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 81dda0ea3..7c9f70cc8 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -4979,6 +4979,60 @@ class FormHelperTest extends CakeTestCase { $this->assertTags($result, $expected); } +/** + * test that select() with numeric label of optiongroup. + * + * @return void + */ + public function testSelectOptionGroupWithNumericLabel() { + $options = array( + 1 => array( + 1 => '1Foo', + 2 => '2Bar', + 3 => '3Baz', + 4 => '1', + 5 => '2', + 6 => '3', + 7 => 1, + 8 => 2, + 9 => 3, + ), + 2 => array( + 11 => '1Foo', + 12 => '2Bar', + 13 => '3Baz', + 14 => '1', + 15 => '2', + 16 => '3', + 17 => 1, + 18 => 2, + 19 => 3, + ), + ); + $result = $this->Form->select('Model.field', $options, array('empty' => false)); + $expected = array( + 'select' => array('name' => 'data[Model][field]', 'id' => 'ModelField'), + array('optgroup' => array('label' => '1')), + array('option' => array('value' => '1')), '1Foo', '/option', + array('option' => array('value' => '2')), '2Bar', '/option', + array('option' => array('value' => '3')), '3Baz', '/option', + array('option' => array('value' => '6')), '3', '/option', + array('option' => array('value' => '9')), '3', '/option', + '/optgroup', + array('optgroup' => array('label' => '2')), + array('option' => array('value' => '11')), '1Foo', '/option', + array('option' => array('value' => '12')), '2Bar', '/option', + array('option' => array('value' => '13')), '3Baz', '/option', + array('option' => array('value' => '14')), '1', '/option', + array('option' => array('value' => '16')), '3', '/option', + array('option' => array('value' => '17')), '1', '/option', + array('option' => array('value' => '19')), '3', '/option', + '/optgroup', + '/select' + ); + $this->assertTags($result, $expected); + } + /** * test that select() with optiongroups listens to the escape param. * diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 9133a4c3f..0d6dd7dd5 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -2832,7 +2832,7 @@ class FormHelper extends AppHelper { } else { $select[] = $this->Html->useTag('optiongroupend'); } - $parents[] = $name; + $parents[] = (string)$name; } $select = array_merge($select, $this->_selectOptions( $title, $parents, $showParents, $attributes