Skip to content
Permalink
Browse files

Make h() return all non string scalars unchanged.

Earlier floats were converted to string.
  • Loading branch information...
ADmad committed Apr 29, 2018
1 parent ad32913 commit 8a56d7bf3207ea97b14de81296be0d078665f302
Showing with 28 additions and 1 deletion.
  1. +1 −1 src/Core/functions.php
  2. +27 −0 tests/TestCase/Core/FunctionsTest.php
@@ -51,7 +51,7 @@ function h($text, $double = true, $charset = null)
} else {
$text = '(object)' . get_class($text);
}
} elseif ($text === null || is_bool($text) || is_int($text)) {
} elseif ($text === null || is_scalar($text)) {
return $text;
}
@@ -14,6 +14,7 @@
*/
namespace Cake\Test\TestCase\Core;
use Cake\Http\Response;
use Cake\TestSuite\TestCase;
/**
@@ -43,6 +44,32 @@ public function testEnv()
$this->assertEquals('0', env('ZERO', '1'));
}
/**
* Test cases for h()
*
* @return void
* @dataProvider hInputProvider
*/
public function testH($value, $expected)
{
$result = h($value);
$this->assertSame($expected, $result);
}
public function hInputProvider()
{
return [
['i am clean', 'i am clean'],
['i "need" escaping', 'i "need" escaping'],
[null, null],
[1, 1],
[1.1, 1.1],
[new \stdClass, '(object)stdClass'],
[new Response(), ''],
[['clean', '"clean-me'], ['clean', '"clean-me']],
];
}
/**
* Test error messages coming out when deprecated level is on, manually setting the stack frame
*

0 comments on commit 8a56d7b

Please sign in to comment.
You can’t perform that action at this time.