mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 06:42:41 +01:00
Work around "mb_check_encoding(<stringlike-object>)" warning in particular versions of PHP
Summary: Fixes T13527. Some versions of PHP strictly require that we pass a string value, and reject "stringlike" objects (objects which implement "__toString()"). Test Plan: Ran unit test, although this is somewhat aspirational because my local PHP version isn't affected. Maniphest Tasks: T13527 Differential Revision: https://secure.phabricator.com/D21193
This commit is contained in:
parent
284139a24e
commit
696ec3f975
2 changed files with 13 additions and 0 deletions
|
@ -824,4 +824,13 @@ final class PhutilUTF8TestCase extends PhutilTestCase {
|
||||||
phutil_set_system_locale($original_locale);
|
phutil_set_system_locale($original_locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUTF8StringlikeObjects() {
|
||||||
|
// See T13527. In some versions and configurations of PHP, passing an
|
||||||
|
// object which implements "__toString()" to "mb_check_encoding()" could
|
||||||
|
// fail.
|
||||||
|
$any_stringlike_object = new PhutilURI('/');
|
||||||
|
|
||||||
|
$this->assertTrue(phutil_is_utf8($any_stringlike_object));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,6 +95,10 @@ function phutil_is_utf8_with_only_bmp_characters($string) {
|
||||||
*/
|
*/
|
||||||
function phutil_is_utf8($string) {
|
function phutil_is_utf8($string) {
|
||||||
if (function_exists('mb_check_encoding')) {
|
if (function_exists('mb_check_encoding')) {
|
||||||
|
// See T13527. In some versions of PHP, "mb_check_encoding()" strictly
|
||||||
|
// requires a string parameter.
|
||||||
|
$string = phutil_string_cast($string);
|
||||||
|
|
||||||
// If mbstring is available, this is significantly faster than using PHP.
|
// If mbstring is available, this is significantly faster than using PHP.
|
||||||
return mb_check_encoding($string, 'UTF-8');
|
return mb_check_encoding($string, 'UTF-8');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue