diff options
| author | Christoph M. Becker <cmbecker69@gmx.de> | 2019-09-30 13:04:24 +0200 |
|---|---|---|
| committer | Christoph M. Becker <cmbecker69@gmx.de> | 2019-09-30 13:04:54 +0200 |
| commit | 2046b3ce4fd09063fdbe1eaf1824b5a1d0bed125 (patch) | |
| tree | d2bbe8076cf9673b75835cd772844979f9c12f00 | |
| parent | e546d721e8c61fb1218335dc75b1874033c3ca24 (diff) | |
| parent | 45db6fa567b65e7ecd49b59527904fd8566ad813 (diff) | |
| download | php-git-2046b3ce4fd09063fdbe1eaf1824b5a1d0bed125.tar.gz | |
Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2:
Fix #78609: mb_check_encoding() no longer supports stringable objects
| -rw-r--r-- | NEWS | 2 | ||||
| -rw-r--r-- | ext/mbstring/mbstring.c | 28 | ||||
| -rw-r--r-- | ext/mbstring/tests/bug78609.phpt | 20 |
3 files changed, 30 insertions, 20 deletions
@@ -17,6 +17,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) - Mysqlnd: . Fixed bug #78525 (Memory leak in pdo when reusing native prepared diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index a7edb48d2b..a42373e5cb 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -4823,27 +4823,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 index 0000000000..11f9b06f13 --- /dev/null +++ b/ext/mbstring/tests/bug78609.phpt @@ -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) |
