Browse Source

Prevent booleans from being encoded (converted to strings) by h() function, helps prevent accidental fatal errors in some PHP versions around 5.2.9

Simon East 13 years ago
parent
commit
1ea457e40e
2 changed files with 11 additions and 0 deletions
  1. 9 0
      lib/Cake/Test/Case/BasicsTest.php
  2. 2 0
      lib/Cake/basics.php

+ 9 - 0
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);

+ 2 - 0
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;