Bug #77093 [ReO]: mb_ereg_replace() does not work with SJIS-win(cp932)
| From: | yohgaki@php.net | Date: | Sat, 03 Nov 2018 23:22:13 +0000 |
| Subject: | Bug #77093 [ReO]: mb_ereg_replace() does not work with SJIS-win(cp932) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-217812@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77093&edit=1
ID: 77093
Updated by: yohgaki@php.net
Reported by: ryosuke dot kobayashi at fujisystems dot co dot jp
Summary: mb_ereg_replace() does not work with SJIS-win(cp932)
Status: Re-Opened
Type: Bug
Package: mbstring related
Operating System: Linux
PHP Version: 7.2.11
Block user comment: N
Private report: N
New Comment:
I suppose returning exact encoding, i.e. SJIS-win, from
_php_mb_regex_mbctype2name(MBREX(current_mbctype)) would fix this bug.
Previous Comments:
------------------------------------------------------------------------
[2018-11-03 23:16:00] yohgaki@php.net
I briefly checked code. It seems the difference came from supported encoding between mbstring and
Onigruma. Mbstring has 'SJIS-win' encoding while Oniguruma has only 'SJIS'. Any
SJIS valiants are validated as 'SJIS'.
As a result, Current (newer) code is trying to validate 'SJIS-win' as 'SJIS'
which will fail in certain cases.
Following code should be fixed to address this bug. i.e. php_mb_check_encoding() needs
'SJIS-win' from '_php_mb_regex_mbctype2name(MBREX(current_mbctype))' in this
case, not 'SJIS'.
php_mbregex.c
if (!php_mb_check_encoding(
string,
string_len,
_php_mb_regex_mbctype2name(MBREX(current_mbctype))
)) {
Using 'SJIS' as mbregex encoding wouldn't fix issue.
https://3v4l.org/P56Zg
There should be other issue.
------------------------------------------------------------------------
[2018-11-03 03:34:33] yohgaki@php.net
It seems encoding validation is failing somehow and returning FALSE for it.
------------------------------------------------------------------------
[2018-11-02 09:54:14] cmb@php.net
<https://3v4l.org/m6JZe> looks like a bug.
------------------------------------------------------------------------
[2018-11-02 09:17:44] ryosuke dot kobayashi at fujisystems dot co dot jp
Thank you for your reply.
>You need to use mb_regex_encoding() to specify the mb_regex encoding.
Exactry... I forgotted to add this cuz my Environment works on SJIS-win.
I fixed my test code, and tried it here.
https://3v4l.org/m6JZe
Now, the problem has occurd I wanted to point out.
Best regards.
------------------------------------------------------------------------
[2018-11-02 08:06:14] yohgaki@php.net
Mbstring's internal and regex encoding is independent.
Before 5.6/7.0, mbregex's default encoding was EUC-JP which ISO 8859-1 compatible. So it worked
in most cases. Since 5.6/7.0, I made default to UTF-8.
https://wiki.php.net/rfc/default_encoding
Anyway, to make sure correct operations, you'll need to set correct encoding via
mb_regex_encoding() for mb_ereg*(). I might have to take a look at where the difference came from,
though.
If you notice anything wrong, please let us know.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=77093
--
Edit this bug report at https://bugs.php.net/bug.php?id=77093&edit=1