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).
This commit is contained in:
Guillaume Lafarge 2014-04-10 20:19:32 +02:00
parent f9a6c1905b
commit db450a96e9

View file

@ -192,7 +192,7 @@ class Hash {
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] === '/') {