Bug #79986 [PATCH]: str_ireplace bug with diacritics characters
| From: | cmb@php.net | Date: | Tue, 18 Aug 2020 11:30:21 +0000 |
| Subject: | Bug #79986 [PATCH]: str_ireplace bug with diacritics characters | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-228639@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79986&edit=1
ID: 79986
Patch added by: cmb@php.net
Reported by: cryptooman at yandex dot ru
Summary: str_ireplace bug with diacritics characters
Status: Verified
Type: Bug
Package: Strings related
Operating System: Ubuntu 18.04
PHP Version: 7.2.33
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
The following pull request has been associated:
Patch Name: Fix #79986: str_ireplace bug with diacritics characters
On GitHub: https://github.com/php/php-src/pull/6007
Patch: https://github.com/php/php-src/pull/6007.patch
Previous Comments:
------------------------------------------------------------------------
[2020-08-18 10:19:12] cmb@php.net
Actually, str_ireplace() (like several other string functions) is
supposed to be locale aware, but only supporting single byte
locales properly; this is not documented yet.
The implementation doesn't match that expectation, though[1].
Anyhow, assuming that you're dealing with UTF-8, you may want to
use preg_replace() instead[2].
[1] <https://3v4l.org/GVECA>
[2] <https://3v4l.org/2D4ZJ>
------------------------------------------------------------------------
[2020-08-17 18:03:50] cryptooman at yandex dot ru
Description:
------------
---
From manual page: https://php.net/function.str-ireplace
---
Function str_ireplace fails to replace diacritics characters if case (lower or upper) of search
pattern does not match case of characters in subject string. Affected languages: french, russian,
german, spanish, etc. Short php-script sample provided below.
Test script:
---------------
<?php
// French
// Result: 1Ã 2Ã 3Ã 4Ã
// Expect: 11 22 33 44
echo str_ireplace(['à ', 'â', 'ä', 'æ'],
['1', '2', '3', '4'], 'à à âà äÃ
æÃ') . PHP_EOL;
// Result: à 1 â2 ä3 æ4
// Expect: 11 22 33 44
echo str_ireplace(['Ã', 'Ã', 'Ã', 'Ã'],
['1', '2', '3', '4'], 'à à âà äÃ
æÃ') . PHP_EOL;
// Russian
// Result: 1Ð 2Ð
// Expect: 11 22
echo str_ireplace(['Ñ', 'й'], ['1', '2'],
'ÑРйÐ') . PHP_EOL;
// Result: Ñ1 й2
// Expect: 11 22
echo str_ireplace(['Ð', 'Ð'], ['1', '2'],
'ÑРйÐ') . PHP_EOL;
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79986&edit=1