Fixing handling of true, false, null in object encoding.

This commit is contained in:
mark_story 2009-03-13 19:37:57 -04:00
parent 2f40804d21
commit 518e567458
2 changed files with 12 additions and 0 deletions

View file

@ -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);
}

View file

@ -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);
}
}
}