From 1ea457e40e1613ea7a052ae8ce5bc3b6ddc37bd6 Mon Sep 17 00:00:00 2001 From: Simon East Date: Fri, 20 Jul 2012 12:37:36 +1000 Subject: [PATCH] Prevent booleans from being encoded (converted to strings) by h() function, helps prevent accidental fatal errors in some PHP versions around 5.2.9 --- lib/Cake/Test/Case/BasicsTest.php | 9 +++++++++ lib/Cake/basics.php | 2 ++ 2 files changed, 11 insertions(+) diff --git a/lib/Cake/Test/Case/BasicsTest.php b/lib/Cake/Test/Case/BasicsTest.php index c218f1a9e..407986919 100644 --- a/lib/Cake/Test/Case/BasicsTest.php +++ b/lib/Cake/Test/Case/BasicsTest.php @@ -225,6 +225,15 @@ class BasicsTest extends CakeTestCase { '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); diff --git a/lib/Cake/basics.php b/lib/Cake/basics.php index 13af9317f..1dc81245e 100644 --- a/lib/Cake/basics.php +++ b/lib/Cake/basics.php @@ -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;