mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Fixing handling of true, false, null in object encoding.
This commit is contained in:
parent
2f40804d21
commit
518e567458
2 changed files with 12 additions and 0 deletions
|
@ -360,6 +360,12 @@ class JsBaseEngineHelper extends AppHelper {
|
|||
if ($this->useNative) {
|
||||
$rt = json_encode($data);
|
||||
} else {
|
||||
if (is_null($data)) {
|
||||
return 'null';
|
||||
}
|
||||
if (is_bool($data)) {
|
||||
return $data ? 'true' : 'false';
|
||||
}
|
||||
if (is_array($data)) {
|
||||
$keys = array_keys($data);
|
||||
}
|
||||
|
|
|
@ -279,6 +279,12 @@ class JsBaseEngineTestCase extends CakeTestCase {
|
|||
));
|
||||
$expected = '{"2007":{"Spring":{"1":{"id":1,"name":"Josh"},"2":{"id":2,"name":"Becky"}},"Fall":{"1":{"id":1,"name":"Josh"},"2":{"id":2,"name":"Becky"}}},"2006":{"Spring":{"1":{"id":1,"name":"Josh"},"2":{"id":2,"name":"Becky"}},"Fall":{"1":{"id":1,"name":"Josh"},"2":{"id":2,"name":"Becky"}}}}';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
foreach (array('true' => true, 'false' => false, 'null' => null) as $expected => $data) {
|
||||
$result = $this->JsEngine->object($data);
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue