Skip to content

Commit

Permalink
Stringify values to avoid trap of in_array() type juggling
Browse files Browse the repository at this point in the history
  • Loading branch information
kanonji committed Feb 27, 2017
1 parent beff117 commit 3978f87
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
54 changes: 54 additions & 0 deletions lib/Cake/Test/Case/View/Helper/FormHelperTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4979,6 +4979,60 @@ public function testSelectBoolean() {
$this->assertTags($result, $expected); $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. * test that select() with optiongroups listens to the escape param.
* *
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/View/Helper/FormHelper.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2832,7 +2832,7 @@ protected function _selectOptions($elements = array(), $parents = array(), $show
} else { } else {
$select[] = $this->Html->useTag('optiongroupend'); $select[] = $this->Html->useTag('optiongroupend');
} }
$parents[] = $name; $parents[] = (string)$name;
} }
$select = array_merge($select, $this->_selectOptions( $select = array_merge($select, $this->_selectOptions(
$title, $parents, $showParents, $attributes $title, $parents, $showParents, $attributes
Expand Down

0 comments on commit 3978f87

Please sign in to comment.