Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14403347
D21193.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D21193.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D21193: Work around "mb_check_encoding(<stringlike-object>)" warning in particular versions of PHP
Attached
Detach File
Event Timeline
Log In to Comment