mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Fix Hash::extract() not matching 1/0 to true/false.
Historically [prop=1] has matched prop=true as well. This restores that and also fixes [prop=0] not finding falsey values. This makes the typing less strict in Hash::extract() but I don't think it is unreasonable given PHP's type juggling. Refs #3288
This commit is contained in:
parent
d8b4c3967c
commit
fa19c34580
2 changed files with 13 additions and 1 deletions
|
@ -868,10 +868,19 @@ class HashTest extends CakeTestCase {
|
|||
'active' => false
|
||||
),
|
||||
);
|
||||
$result = Hash::extract($users, '{n}[active=0]');
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertEquals($users[2], $result[0]);
|
||||
|
||||
$result = Hash::extract($users, '{n}[active=false]');
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertEquals($users[2], $result[0]);
|
||||
|
||||
$result = Hash::extract($users, '{n}[active=1]');
|
||||
$this->assertCount(2, $result);
|
||||
$this->assertEquals($users[0], $result[0]);
|
||||
$this->assertEquals($users[1], $result[1]);
|
||||
|
||||
$result = Hash::extract($users, '{n}[active=true]');
|
||||
$this->assertCount(2, $result);
|
||||
$this->assertEquals($users[0], $result[0]);
|
||||
|
|
|
@ -208,7 +208,10 @@ class Hash {
|
|||
if (isset($data[$attr])) {
|
||||
$prop = $data[$attr];
|
||||
}
|
||||
if ($prop === true || $prop === false) {
|
||||
$isBool = is_bool($prop);
|
||||
if ($isBool && is_numeric($val)) {
|
||||
$prop = $prop ? '1' : '0';
|
||||
} elseif ($isBool) {
|
||||
$prop = $prop ? 'true' : 'false';
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue