Bug #77557 [Ver]: mb_regex_replace does not handle backreferences if regex-encoding is UTF-32

From: Date: Mon, 11 Feb 2019 16:33:52 +0000
Subject: Bug #77557 [Ver]: mb_regex_replace does not handle backreferences if regex-encoding is UTF-32
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219505@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77557&edit=1

 ID:                 77557
 Updated by:         nikic@php.net
 Reported by:        codes at designsandcodes dot com
 Summary:            mb_regex_replace does not handle backreferences if
                     regex-encoding is UTF-32
 Status:             Verified
 Type:               Bug
 Package:            mbstring related
 Operating System:   Windows 10, Ubuntu 16.04
 PHP Version:        7.2
 Block user comment: N
 Private report:     N

 New Comment:

Looks like the code assumes that the encoding is ASCII-compatible (like UTF-8). There might not be a
simple fix for this one.


Previous Comments:
------------------------------------------------------------------------
[2019-02-02 19:05:22] cmb@php.net

This issue is not PHP 7.3 specific[1].

[1] <https://3v4l.org/KqU5d>

------------------------------------------------------------------------
[2019-02-02 02:52:57] codes at designsandcodes dot com

Description:
------------
Per summary, backreferences are not properly replaced if the regex encoding is any of the UTF-32
flavors (BE, LE, UCS-4).  All 3 parameters (pattern, replace, subject) are being presented in the
correct UTF-32 flavor; replace is being returned unmodified.

Test script:
---------------
$regexEncoding = 'UTF-32';
mb_regex_encoding( $regexEncoding );
var_export( mb_ereg_replace( mb_convert_encoding( '.+', $regexEncoding ),
mb_convert_encoding( "the \\0", $regexEncoding ), mb_convert_encoding( 'dog',
$regexEncoding ) ) );

Expected result:
----------------
'' . "\0" . '' . "\0" . '' . "\0" .
't' . "\0" . '' . "\0" . '' . "\0" .
'h' . "\0" . '' . "\0" . '' . "\0" .
'e' . "\0" . '' . "\0" . '' . "\0" .
' ' . "\0" . '' . "\0" . '' . "\0" .
'd' . "\0" . '' . "\0" . '' . "\0" .
'o' . "\0" . '' . "\0" . '' . "\0" .
'g'

e.g., "the dog" in UTF-32 encoding

Actual result:
--------------
'' . "\0" . '' . "\0" . '' . "\0" .
't' . "\0" . '' . "\0" . '' . "\0" .
'h' . "\0" . '' . "\0" . '' . "\0" .
'e' . "\0" . '' . "\0" . '' . "\0" .
' ' . "\0" . '' . "\0" . '' . "\0" .
'\\' . "\0" . '' . "\0" . '' . "\0" .
'0'

e.g., "\\0" in UTF-32 encoding


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=77557&edit=1


Thread (3 messages)

« previous php.bugs (#219505) next »