Skip to content

Commit

Permalink
Correctly handle field name for [] suffixed fields.
Browse files Browse the repository at this point in the history
SecurityComponent was generating a different name for these fields. This
format matches the end result of `thing.prop[0]` as well, which is what
`thing.prop[]` is getting at.

Refs #8170
  • Loading branch information
markstory committed Feb 5, 2016
1 parent 2d54b2a commit 8cc7d38
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/View/Helper/FormHelper.php
Expand Up @@ -2435,7 +2435,7 @@ protected function _secureFieldName($name)
$parts = array_map(function ($el) {
return trim($el, ']');
}, $parts);
return $parts;
return array_filter($parts, 'strlen');
}

/**
Expand Down
6 changes: 5 additions & 1 deletion tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -1746,7 +1746,11 @@ public function testSecuredInputCustomName()
$this->Form->select('select_box', [1, 2], [
'name' => 'Option[General.select_role]',
]);
$expected = ['Option.General.default_role', 'Option.General.select_role'];
$expected[] = 'Option.General.select_role';
$this->assertEquals($expected, $this->Form->fields);

$this->Form->text('other.things[]');
$expected[] = 'other.things';
$this->assertEquals($expected, $this->Form->fields);
}

Expand Down

0 comments on commit 8cc7d38

Please sign in to comment.