Permalink
Browse files

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

  • Loading branch information...
1 parent 2f40804 commit 518e567458e7f9bf2ae4f9535631cf137813a7fc @markstory markstory committed Mar 13, 2009
Showing with 12 additions and 0 deletions.
  1. +6 −0 cake/libs/view/helpers/js.php
  2. +6 −0 cake/tests/cases/libs/view/helpers/js.test.php
@@ -360,6 +360,12 @@ function object($data = array(), $options = array()) {
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 @@ function testObject() {
));
$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);
+ }
+
}
}

0 comments on commit 518e567

Please sign in to comment.