Bug #81437 [Opn]: mb_strtchr cutting differently on php 8.1
Edit report at https://bugs.php.net/bug.php?id=81437&edit=1
ID: 81437
Updated by: nicolasgrekas@php.net
Reported by: nicolasgrekas@php.net
Summary: mb_strtchr cutting differently on php 8.1
Status: Open
Type: Bug
Package: *General Issues
PHP Version: 8.1.0RC1
Block user comment: N
Private report: N
New Comment:
I'm wondering why mb_strrchr() needs to do any validation, but anyway: works for me, let's
close if that's fine to you.
Previous Comments:
------------------------------------------------------------------------
[2021-09-20 14:29:13] nikic@php.net
This should explain what is going on here: https://3v4l.org/lH2KZ
In PHP 8.1 the ASCII validation is stricter and input code units over 0x80 are considered as
illegal. This means that both é and à become ?? after illegal character substitution.
If the desired behavior was to do a raw binary search, then the right encoding to use would be 8bit
rather than ASCII.
I think the only open question here is whether we should make this fail in a different way.
Generally mbstring operates on the GIGO principle when it comes to input strings that are
incorrectly encoded, because validating them would add significant overhead to all operations. In
this case we do already validate it due to conversion to UTF-8, so we could always report no match
in that case. But we wouldn't be able to guarantee that behavior either, because a future
optimization to skip UTF-8 conversion for single-byte encodings would actually get back to the
historical behavior.
Basically, if mb_check_encoding() for an input to an mbstring function returns false, behavior is
undefined and is going to change depending on implementation details.
------------------------------------------------------------------------
[2021-09-14 13:45:11] nicolasgrekas@php.net
It could return false, but that's not the historical behavior apparently :)
------------------------------------------------------------------------
[2021-09-14 13:34:47] cmb@php.net
Shouldn't that return false, since neither haystack not needle are
ASCII encoded?
------------------------------------------------------------------------
[2021-09-14 13:22:47] nicolasgrekas@php.net
Description:
------------
echo mb_strrchr('déjà déjà ', 'é', false, 'ASCII');
echoes "à " on 8.1 but echoes "éjà " on previous versions.
See https://3v4l.org/jujrP
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81437&edit=1
Thread (6 messages)