Fix passing a null input to h function

Fix the following deprecation warning: Deprecated (8192): htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated [APP/Vendor/cakephp/cakephp/lib/Cake/basics.php, line 231]
This commit is contained in:
Diego Surita 2023-12-19 14:08:56 +00:00 committed by Kamil Wylegala
parent 219d13c0f0
commit 8473730ba2
2 changed files with 5 additions and 0 deletions

View file

@ -243,6 +243,9 @@ class BasicsTest extends CakeTestCase {
$obj = new CakeResponse(array('body' => 'Body content')); $obj = new CakeResponse(array('body' => 'Body content'));
$result = h($obj); $result = h($obj);
$this->assertEquals('Body content', $result); $this->assertEquals('Body content', $result);
$result = h(null);
$this->assertEquals('', $result);
} }
/** /**

View file

@ -215,6 +215,8 @@ if (!function_exists('h')) {
} }
} elseif (is_bool($text)) { } elseif (is_bool($text)) {
return $text; return $text;
} elseif (is_null($text)) {
return '';
} }
static $defaultCharset = false; static $defaultCharset = false;