merged branch MaxVandervelde/fix/namespaced-parameter-issue (PR #7586)

This PR was merged into the 2.1 branch.

Discussion
----------

[HttpFoundation] Fixed bug in key searching for NamespacedAttributeBag

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #7564
| License       | MIT
| Doc PR        | N/A

Fixed a bug in NamespacedAttributeBag causing a result to be falsely found when
the last key of the attribute matched the last of the queried name regardless of
if the key did not exist in the search.
Added Tests to demonstrate the issue and resolved by setting keys to null when
iterating through query and returning proper responses in the case that the
given array does in fact not exist.

Commits
-------

0f0c29c [HttpFoundation] Fixed bug in key searching for NamespacedAttributeBag
This commit is contained in:
Fabien Potencier 2013-04-12 08:49:49 +02:00
commit 0d32445414
2 changed files with 12 additions and 6 deletions

View File

@ -46,6 +46,10 @@ class NamespacedAttributeBag extends AttributeBag
$attributes = $this->resolveAttributePath($name);
$name = $this->resolveKey($name);
if (null === $attributes) {
return false;
}
return array_key_exists($name, $attributes);
}
@ -57,6 +61,10 @@ class NamespacedAttributeBag extends AttributeBag
$attributes = $this->resolveAttributePath($name);
$name = $this->resolveKey($name);
if (null === $attributes) {
return $default;
}
return array_key_exists($name, $attributes) ? $attributes[$name] : $default;
}
@ -120,12 +128,8 @@ class NamespacedAttributeBag extends AttributeBag
unset($parts[count($parts)-1]);
foreach ($parts as $part) {
if (!array_key_exists($part, $array)) {
if (!$writeContext) {
return $array;
}
$array[$part] = array();
if (null !== $array && !array_key_exists($part, $array)) {
$array[$part] = $writeContext ? array() : null;
}
$array = & $array[$part];

View File

@ -160,8 +160,10 @@ class NamespacedAttributeBagTest extends \PHPUnit_Framework_TestCase
array('csrf.token/b', '4321', true),
array('category', array('fishing' => array('first' => 'cod', 'second' => 'sole')), true),
array('category/fishing', array('first' => 'cod', 'second' => 'sole'), true),
array('category/fishing/missing/first', null, false),
array('category/fishing/first', 'cod', true),
array('category/fishing/second', 'sole', true),
array('category/fishing/missing/second', null, false),
array('user2.login', null, false),
array('never', null, false),
array('bye', null, false),