Skip to content

Commit

Permalink
Fixing handling of true, false, null in object encoding.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Mar 13, 2009
1 parent 2f40804 commit 518e567
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cake/libs/view/helpers/js.php
Expand Up @@ -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);
}
Expand Down
6 changes: 6 additions & 0 deletions cake/tests/cases/libs/view/helpers/js.test.php
Expand Up @@ -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);
}

}
}

Expand Down

0 comments on commit 518e567

Please sign in to comment.