Bug #77607 [ReO]: mb_substr does not respect mb_substitution_character

From: Date: Sat, 23 Feb 2019 06:14:45 +0000
Subject: Bug #77607 [ReO]: mb_substr does not respect mb_substitution_character
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219712@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77607&edit=1 ID: 77607 Updated by: jhdxr@php.net Reported by: legale dot legale at gmail dot com Summary: mb_substr does not respect mb_substitution_character Status: Re-Opened Type: Bug Package: mbstring related Operating System: Linux PHP Version: 7.3.2 Block user comment: N Private report: N New Comment: The document says "This setting affects mb_convert_encoding(), mb_convert_variables(), mb_output_handler(), and mb_send_mail(). " so I'll say it's expected. It's another topic whether we want to apply mb_substitution_character to more functions. Previous Comments: ------------------------------------------------------------------------ [2019-02-12 10:03:59] nikic@php.net What *is* buggy here though is that mb_substr() apparently does not respect mb_substitute_character() at all. In fact, I don't think any of the filters created inside libmbfl rather than mbstring do :( ------------------------------------------------------------------------ [2019-02-12 09:56:41] nikic@php.net This looks correct to me. 0x003f is '?' which is the default substitution character (though I think we should change the default to U+FFFD instead). See also http://php.net/manual/en/function.mb-substitute-character.php. ------------------------------------------------------------------------ [2019-02-11 22:23:07] legale dot legale at gmail dot com Description: ------------ Processing bad utf-16 strings leads to unexpected source data changes. Test script: --------------- <?php $bad_utf16be = pack("H*", "dc00dc00"); /* two 1 byte chars */ $good_utf16be = pack("H*", "d800dc00"); /* one 2 bytes char */ $utf16_string = $bad_utf16be . $good_utf16be; /* take second and third char */ $second = mb_substr($utf16_string, 1, 1, "UTF-16BE"); $third = mb_substr($utf16_string, 2, 1, "UTF-16BE"); echo "\nactual:\n"; echo "second UTF-16BE char: 0x". bin2hex($second) . PHP_EOL; echo "third UTF-16BE char: 0x". bin2hex($third) . PHP_EOL; echo "\nexpected:\n"; echo "second UTF-16BE char: 0xdc00" . PHP_EOL; echo "third UTF-16BE char: 0xd800dc00" . PHP_EOL; Expected result: ---------------- expected: second UTF-16BE char: 0xdc00 third UTF-16BE char: 0xd800dc00 Actual result: -------------- actual: second UTF-16BE char: 0x003f third UTF-16BE char: 0xd800dc00 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77607&edit=1

« previous php.bugs (#219712) next »