]> granicus.if.org Git - php/commitdiff
Fix #78609: mb_check_encoding() no longer supports stringable objects
authorChristoph M. Becker <cmbecker69@gmx.de>
Mon, 30 Sep 2019 09:07:03 +0000 (11:07 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Mon, 30 Sep 2019 10:42:04 +0000 (12:42 +0200)
We apply type juggling for other types than array.

NEWS
ext/mbstring/mbstring.c
ext/mbstring/tests/bug78609.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index b0be6e40f5c8ca13879a46d40eeb5639fa84b371..89a65dd49e7ba0d549f886b57481d02f4c2ebb25 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,8 @@ PHP                                                                        NEWS
 - MBString:
   . Fixed bug #78579 (mb_decode_numericentity: args number inconsistency).
     (cmb)
+  . Fixed bug #78609 (mb_check_encoding() no longer supports stringable
+    objects). (cmb)
 
 - Standard:
   . Fixed bug #76342 (file_get_contents waits twice specified timeout).
index 173539f4b8c9687e8343b4526ff5328d6042b105..516b6143241fa32b014ae581f529c1b8bc98a5b2 100644 (file)
@@ -5027,27 +5027,15 @@ PHP_FUNCTION(mb_check_encoding)
                RETURN_FALSE;
        }
 
-       switch(Z_TYPE_P(input)) {
-               case IS_LONG:
-               case IS_DOUBLE:
-               case IS_NULL:
-               case IS_TRUE:
-               case IS_FALSE:
-                       RETURN_TRUE;
-                       break;
-               case IS_STRING:
-                       if (!php_mb_check_encoding(Z_STRVAL_P(input), Z_STRLEN_P(input), enc ? ZSTR_VAL(enc): NULL)) {
-                               RETURN_FALSE;
-                       }
-                       break;
-               case IS_ARRAY:
-                       if (!php_mb_check_encoding_recursive(HASH_OF(input), enc)) {
-                               RETURN_FALSE;
-                       }
-                       break;
-               default:
-                       php_error_docref(NULL, E_WARNING, "Input is something other than scalar or array");
+       if (Z_TYPE_P(input) == IS_ARRAY) {
+               if (!php_mb_check_encoding_recursive(HASH_OF(input), enc)) {
                        RETURN_FALSE;
+               }
+       } else {
+               convert_to_string(input);
+               if (!php_mb_check_encoding(Z_STRVAL_P(input), Z_STRLEN_P(input), enc ? ZSTR_VAL(enc): NULL)) {
+                       RETURN_FALSE;
+               }
        }
        RETURN_TRUE;
 }
diff --git a/ext/mbstring/tests/bug78609.phpt b/ext/mbstring/tests/bug78609.phpt
new file mode 100644 (file)
index 0000000..11f9b06
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+Bug #78609 (mb_check_encoding() no longer supports stringable objects)
+--SKIPIF--
+<?php
+if (!extension_loaded('mbstring')) die('skip mbstring extension not available');
+?>
+--FILE--
+<?php
+class Foo
+{
+    public function __toString()
+    {
+        return 'string_representation';
+    }
+}
+
+var_dump(mb_check_encoding(new Foo, 'UTF-8'));
+?>
+--EXPECT--
+bool(true)