Skip to content
Permalink
Browse files

Handle case where a visible input shares a name with an invisible one.

If a visible input is created *after* a hidden input was created, the
form would always blackhole unless the visible input had the same value
as the hidden input.

Refs #7274
  • Loading branch information...
markstory committed Aug 23, 2015
1 parent a44d17d commit 143c34bdc10dea7aefa10f5588c45cf0e5352442
Showing with 26 additions and 0 deletions.
  1. +24 −0 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
  2. +2 −0 lib/Cake/View/Helper/FormHelper.php
@@ -1290,6 +1290,30 @@ public function testFormSecuredInput() {
$this->assertTags($result, $expected);
}
/**
* Test that a hidden field followed by a visible field
* undoes the hidden field locking.
*
* @return void
*/
public function testSecuredInputDuplicate() {
$this->Form->request['_Token'] = array('key' => 'testKey');
$this->assertEquals(array(), $this->Form->fields);
$this->Form->input('text_val', array(
'type' => 'hidden',
'value' => 'some text',
));
$expected = array('text_val' => 'some text');
$this->assertEquals($expected, $this->Form->fields);
$this->Form->input('text_val', array(
'type' => 'text',
));
$expected = array('text_val');
$this->assertEquals($expected, $this->Form->fields);
}
/**
* Test secured inputs with custom names.
*
@@ -661,6 +661,8 @@ protected function _secure($lock, $field = null, $value = null) {
if (!in_array($field, $this->fields)) {
if ($value !== null) {
return $this->fields[$field] = $value;
} elseif (isset($this->fields[$field]) && $value === null) {
unset($this->fields[$field]);
}
$this->fields[] = $field;
}

0 comments on commit 143c34b

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