Skip to content

Commit 6b197ee

Browse files
Tobias Vorwachsalexdowad
authored andcommitted
mbstring: fix missing copying of detect_order_list to current_detect_order_list on ini_set('mbstring.detect_order', string)
Closes phpGH-20523.
1 parent 1848bcd commit 6b197ee

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ PHP NEWS
2020
. Fixed bug GH-20483 (ASAN stack overflow with fiber.stack_size INI
2121
small value). (David Carlier)
2222

23+
- Mbstring:
24+
. ini_set() with mbstring.detect_order changes the order of mb_detect_order
25+
as intended, since mbstring.detect_order is an INI_ALL setting. (tobee94)
26+
2327
- Opcache:
2428
. Fixed bug GH-20051 (apache2 shutdowns when restart is requested during
2529
preloading). (Arnaud, welcomycozyhom)

UPGRADING

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ PHP 8.6 UPGRADE NOTES
9898
When used along with ZEND_JIT_DEBUG_TRACE_EXIT_INFO, the source of exit
9999
points is printed in exit info output, in debug builds.
100100

101+
- Mbstring:
102+
. The mbstring.detect_order INI directive now updates the internal detection
103+
order when changed at runtime via ini_set(). Previously, runtime changes
104+
using ini_set() did not take effect for mb_detect_order(). Setting the
105+
directive to NULL or an empty string at runtime now leaves the previously
106+
configured detection order unchanged.
107+
101108
========================================
102109
12. Windows Support
103110
========================================

ext/mbstring/mbstring.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,11 @@ static PHP_INI_MH(OnUpdate_mbstring_detect_order)
718718
}
719719
MBSTRG(detect_order_list) = list;
720720
MBSTRG(detect_order_list_size) = size;
721+
722+
if (stage == PHP_INI_STAGE_RUNTIME) {
723+
php_mb_populate_current_detect_order_list();
724+
}
725+
721726
return SUCCESS;
722727
}
723728
/* }}} */
@@ -5981,6 +5986,11 @@ static void php_mb_populate_current_detect_order_list(void)
59815986
entry[i] = mbfl_no2encoding(src[i]);
59825987
}
59835988
}
5989+
5990+
if (MBSTRG(current_detect_order_list) != NULL) {
5991+
efree(ZEND_VOIDP(MBSTRG(current_detect_order_list)));
5992+
}
5993+
59845994
MBSTRG(current_detect_order_list) = entry;
59855995
MBSTRG(current_detect_order_list_size) = nentries;
59865996
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
--TEST--
2+
Test mb_detect_order() function : ini set changes order
3+
--EXTENSIONS--
4+
mbstring
5+
--INI--
6+
mbstring.detect_order=UTF-8,ISO-8859-15,ISO-8859-1,ASCII
7+
--FILE--
8+
<?php
9+
10+
var_dump( mb_detect_order());
11+
12+
ini_set('mbstring.detect_order', 'UTF-8, ISO-8859-1, ASCII');
13+
14+
var_dump( mb_detect_order());
15+
16+
ini_set('mbstring.detect_order', 'UTF-8');
17+
18+
var_dump( mb_detect_order());
19+
20+
ini_set('mbstring.detect_order', NULL);
21+
22+
var_dump( mb_detect_order());
23+
24+
ini_set('mbstring.detect_order', '');
25+
26+
var_dump( mb_detect_order());
27+
28+
?>
29+
--EXPECT--
30+
array(4) {
31+
[0]=>
32+
string(5) "UTF-8"
33+
[1]=>
34+
string(11) "ISO-8859-15"
35+
[2]=>
36+
string(10) "ISO-8859-1"
37+
[3]=>
38+
string(5) "ASCII"
39+
}
40+
array(3) {
41+
[0]=>
42+
string(5) "UTF-8"
43+
[1]=>
44+
string(10) "ISO-8859-1"
45+
[2]=>
46+
string(5) "ASCII"
47+
}
48+
array(1) {
49+
[0]=>
50+
string(5) "UTF-8"
51+
}
52+
array(1) {
53+
[0]=>
54+
string(5) "UTF-8"
55+
}
56+
array(1) {
57+
[0]=>
58+
string(5) "UTF-8"
59+
}
60+

0 commit comments

Comments
 (0)