[HttpFoundation] Fixed bug in key searching for NamespacedAttributeBag
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. * Updated Syntax of null checks * Fixing missing else case for if statement in write context
This commit is contained in:
parent
7221d25fc4
commit
0f0c29c9bf
@ -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];
|
||||
|
@ -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),
|
||||
|
Reference in New Issue
Block a user