Skip to content

Commit

Permalink
Prevent booleans from being encoded (converted to strings) by h() fun…
Browse files Browse the repository at this point in the history
…ction, helps prevent accidental fatal errors in some PHP versions around 5.2.9
  • Loading branch information
Simon East committed Jul 20, 2012
1 parent f65b52b commit 1ea457e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/Cake/Test/Case/BasicsTest.php
Expand Up @@ -225,6 +225,15 @@ public function testH() {
'n' => ' '
);
$this->assertEquals($expected, $result);

// Test that boolean values are not converted to strings
$result = h(false);
$this->assertFalse($result);

$arr = array('foo' => false, 'bar' => true);
$result = h($arr);
$this->assertFalse($result['foo']);
$this->assertTrue($result['bar']);

$obj = new stdClass();
$result = h($obj);
Expand Down
2 changes: 2 additions & 0 deletions lib/Cake/basics.php
Expand Up @@ -175,6 +175,8 @@ function h($text, $double = true, $charset = null) {
} else {
$text = '(object)' . get_class($text);
}
} elseif (is_bool($text)) {
return $text;
}

static $defaultCharset = false;
Expand Down

0 comments on commit 1ea457e

Please sign in to comment.