Skip to content

Commit 844a2dd

Browse files
committed
Fix #79986: str_ireplace bug with diacritics characters
`tolower()` returns an `int`, so we must not convert to `char` which may be `signed` and as such may be subject to overflow (actually, implementation defined behavior). Closes GH-6007
1 parent fcd26ff commit 844a2dd

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ PHP NEWS
1010
. Fixed bug #80002 (calc free space for new interned string is wrong).
1111
(t-matsuno)
1212

13+
- Standard:
14+
. Fixed bug #79986 (str_ireplace bug with diacritics characters). (cmb)
15+
1316
03 Sep 2020, PHP 7.3.22
1417

1518
- Core:

ext/standard/string.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3156,7 +3156,7 @@ static zend_string* php_char_to_str_ex(zend_string *str, char from, char *to, si
31563156
{
31573157
zend_string *result;
31583158
size_t char_count = 0;
3159-
char lc_from = 0;
3159+
int lc_from = 0;
31603160
const char *source, *source_end= ZSTR_VAL(str) + ZSTR_LEN(str);
31613161
char *target;
31623162

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Bug #79986 (str_ireplace bug with diacritics characters)
3+
--SKIPIF--
4+
<?php
5+
if (!setlocale(LC_ALL, 'de_DE.ISO-8859-1', 'de-DE')) die('skip German locale not available');
6+
?>
7+
--FILE--
8+
<?php
9+
setlocale(LC_ALL, 'de_DE.ISO-8859-1', 'de-DE');
10+
echo str_ireplace(["\xE4", "\xF6", "\xFC"], ['1', '2', '3'], "\xE4\xC4 \xF6\xD6 \xFC\xDC") . PHP_EOL;
11+
?>
12+
--EXPECT--
13+
11 22 33

0 commit comments

Comments
 (0)