Page MenuHomePhabricator

D21193.diff
No OneTemporary

D21193.diff

diff --git a/src/utils/__tests__/PhutilUTF8TestCase.php b/src/utils/__tests__/PhutilUTF8TestCase.php
--- a/src/utils/__tests__/PhutilUTF8TestCase.php
+++ b/src/utils/__tests__/PhutilUTF8TestCase.php
@@ -824,4 +824,13 @@
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));
+ }
+
}
diff --git a/src/utils/utf8.php b/src/utils/utf8.php
--- a/src/utils/utf8.php
+++ b/src/utils/utf8.php
@@ -95,6 +95,10 @@
*/
function phutil_is_utf8($string) {
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.
return mb_check_encoding($string, 'UTF-8');
}

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 24, 2:20 AM (20 h, 8 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6922704
Default Alt Text
D21193.diff (1 KB)

Event Timeline