Skip to content
Permalink
Browse files

Fix Hash type casting

When using comparison with a boolean, as the filter is a string, we have to convert the data boolean to "boolean string" to avoid type-casting troubles.

## Example
```php
$users = [
    [
        'id' => 2,
        'username' => 'johndoe',
        'active' => true
    ],
    [   'id' => 5,
        'username' => 'kevin',
        'active' => true
    ],
    [
        'id' => 9,
        'username' => 'samantha',
        'active' => false
    ],
];
$unactiveUsers = Hash::extract($users, '{n}[active=false]');
print_r($unactiveUsers);
```

This example returns the two unwanted active users because `"false"` is `true` but not `false` :)

I think this pull request will fix this issue by converting true/false boolean to string (to match with our filter).
  • Loading branch information...
glafarge committed Apr 10, 2014
1 parent f9a6c19 commit db450a96e95c35b9328e33bd992c1dcf5837ffb0
Showing with 1 addition and 1 deletion.
  1. +1 −1 lib/Cake/Utility/Hash.php
@@ -192,7 +192,7 @@ protected static function _matches(array $data, $selector) {
return false;
}
$prop = isset($data[$attr]) ? $data[$attr] : null;
$prop = isset($data[$attr]) ? ( is_bool($data[$attr]) ? (($data[$attr]) ? 'true' : 'false') : $data[$attr] ) : null;
// Pattern matches and other operators.
if ($op === '=' && $val && $val[0] === '/') {

0 comments on commit db450a9

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