Skip to content

Commit 06ed6b8

Browse files
committed
Make mb_ereg_replace() pattern argument a string
1 parent ba5d2e6 commit 06ed6b8

File tree

4 files changed

+17
-97
lines changed

4 files changed

+17
-97
lines changed

UPGRADING

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ PHP 8.0 UPGRADE NOTES
9494

9595
. The 'e' modifier for mb_ereg_replace() has been removed.
9696
mb_ereg_replace_callback() should be used instead.
97+
. A non-string pattern argument to mb_ereg_replace() will now be interpreted
98+
as a string instead of an ASCII codepoint. The previous behavior may be
99+
restored with an explicit call to chr().
97100

98101
- SPL:
99102
. SplFileObject::fgetss() has been removed.

ext/mbstring/php_mbregex.c

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -967,8 +967,6 @@ PHP_FUNCTION(mb_eregi)
967967
/* {{{ _php_mb_regex_ereg_replace_exec */
968968
static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOptionType options, int is_callable)
969969
{
970-
zval *arg_pattern_zval;
971-
972970
char *arg_pattern;
973971
size_t arg_pattern_len;
974972

@@ -991,7 +989,6 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
991989
OnigUChar *pos;
992990
OnigUChar *string_lim;
993991
char *description = NULL;
994-
char pat_buf[6];
995992

996993
const mbfl_encoding *enc;
997994

@@ -1010,16 +1007,16 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
10101007
size_t option_str_len = 0;
10111008

10121009
if (!is_callable) {
1013-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zss|s",
1014-
&arg_pattern_zval,
1010+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sss|s",
1011+
&arg_pattern, &arg_pattern_len,
10151012
&replace, &replace_len,
10161013
&string, &string_len,
10171014
&option_str, &option_str_len) == FAILURE) {
10181015
RETURN_FALSE;
10191016
}
10201017
} else {
1021-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zfs|s",
1022-
&arg_pattern_zval,
1018+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sfs|s",
1019+
&arg_pattern, &arg_pattern_len,
10231020
&arg_replace_fci, &arg_replace_fci_cache,
10241021
&string, &string_len,
10251022
&option_str, &option_str_len) == FAILURE) {
@@ -1046,26 +1043,7 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
10461043
php_error_docref(NULL, E_WARNING, "The 'e' option is no longer supported, use mb_ereg_replace_callback instead");
10471044
RETURN_FALSE;
10481045
}
1049-
if (Z_TYPE_P(arg_pattern_zval) == IS_STRING) {
1050-
arg_pattern = Z_STRVAL_P(arg_pattern_zval);
1051-
arg_pattern_len = Z_STRLEN_P(arg_pattern_zval);
1052-
} else {
1053-
php_error_docref(NULL, E_DEPRECATED,
1054-
"Non-string patterns will be interpreted as strings in the future. "
1055-
"Use an explicit chr() call to preserve the current behavior");
1056-
1057-
/* FIXME: this code is not multibyte aware! */
1058-
convert_to_long_ex(arg_pattern_zval);
1059-
pat_buf[0] = (char)Z_LVAL_P(arg_pattern_zval);
1060-
pat_buf[1] = '\0';
1061-
pat_buf[2] = '\0';
1062-
pat_buf[3] = '\0';
1063-
pat_buf[4] = '\0';
1064-
pat_buf[5] = '\0';
1065-
1066-
arg_pattern = pat_buf;
1067-
arg_pattern_len = 1;
1068-
}
1046+
10691047
/* create regex pattern buffer */
10701048
re = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len, options, MBREX(current_mbctype), syntax);
10711049
if (re == NULL) {

ext/mbstring/tests/bug72994.phpt

Lines changed: 0 additions & 21 deletions
This file was deleted.

ext/mbstring/tests/mb_ereg_replace_variation1.phpt

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -96,87 +96,53 @@ foreach($inputs as $input) {
9696

9797
echo "Done";
9898
?>
99-
--EXPECTF--
99+
--EXPECT--
100100
*** Testing mb_ereg_replace() : usage variations ***
101101

102102
-- Iteration 1 --
103-
104-
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
105103
string(10) "string_val"
106104

107105
-- Iteration 2 --
108-
109-
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
110106
string(10) "string_val"
111107

112108
-- Iteration 3 --
113-
114-
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
115109
string(10) "string_val"
116110

117111
-- Iteration 4 --
118-
119-
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
120-
121-
Warning: mb_ereg_replace(): mbregex compile err: invalid code point value in %s on line %d
122-
bool(false)
112+
string(10) "string_val"
123113

124114
-- Iteration 5 --
125-
126-
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
127115
string(10) "string_val"
128116

129117
-- Iteration 6 --
130-
131-
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
132-
133-
Warning: mb_ereg_replace(): mbregex compile err: invalid code point value in %s on line %d
134-
bool(false)
118+
string(10) "string_val"
135119

136120
-- Iteration 7 --
137-
138-
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
139121
string(10) "string_val"
140122

141123
-- Iteration 8 --
142-
143-
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
144124
string(10) "string_val"
145125

146126
-- Iteration 9 --
147-
148-
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
149127
string(10) "string_val"
150128

151129
-- Iteration 10 --
152-
153-
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
154-
string(10) "string_val"
130+
string(120) "string_valsstring_valtstring_valrstring_valistring_valnstring_valgstring_val_string_valvstring_valastring_vallstring_val"
155131

156132
-- Iteration 11 --
157-
158-
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
159-
string(10) "string_val"
133+
string(120) "string_valsstring_valtstring_valrstring_valistring_valnstring_valgstring_val_string_valvstring_valastring_vallstring_val"
160134

161135
-- Iteration 12 --
162-
163-
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
164136
string(10) "string_val"
165137

166138
-- Iteration 13 --
167-
168-
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
169-
string(10) "string_val"
139+
string(120) "string_valsstring_valtstring_valrstring_valistring_valnstring_valgstring_val_string_valvstring_valastring_vallstring_val"
170140

171141
-- Iteration 14 --
172-
173-
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
174142
string(10) "string_val"
175143

176144
-- Iteration 15 --
177-
178-
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
179-
string(10) "string_val"
145+
string(120) "string_valsstring_valtstring_valrstring_valistring_valnstring_valgstring_val_string_valvstring_valastring_vallstring_val"
180146

181147
-- Iteration 16 --
182148
string(120) "string_valsstring_valtstring_valrstring_valistring_valnstring_valgstring_val_string_valvstring_valastring_vallstring_val"
@@ -194,17 +160,11 @@ string(10) "string_val"
194160
string(10) "string_val"
195161

196162
-- Iteration 21 --
197-
198-
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
199163
string(10) "string_val"
200164

201165
-- Iteration 22 --
202-
203-
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
204-
string(10) "string_val"
166+
string(120) "string_valsstring_valtstring_valrstring_valistring_valnstring_valgstring_val_string_valvstring_valastring_vallstring_val"
205167

206168
-- Iteration 23 --
207-
208-
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
209-
string(10) "string_val"
169+
string(120) "string_valsstring_valtstring_valrstring_valistring_valnstring_valgstring_val_string_valvstring_valastring_vallstring_val"
210170
Done

0 commit comments

Comments
 (0)