Skip to content
Permalink
Browse files

Stringify values to avoid trap of in_array() type juggling

  • Loading branch information...
kanonji committed Feb 27, 2017
1 parent beff117 commit 3978f87c581357d8ee8ef088810aace2ffcefa0e
Showing with 55 additions and 1 deletion.
  1. +54 −0 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
  2. +1 −1 lib/Cake/View/Helper/FormHelper.php
@@ -4979,6 +4979,60 @@ public function testSelectBoolean() {
$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.
*
@@ -2832,7 +2832,7 @@ protected function _selectOptions($elements = array(), $parents = array(), $show
} else {
$select[] = $this->Html->useTag('optiongroupend');
}
$parents[] = $name;
$parents[] = (string)$name;
}
$select = array_merge($select, $this->_selectOptions(
$title, $parents, $showParents, $attributes

0 comments on commit 3978f87

Please sign in to comment.
You can’t perform that action at this time.