Skip to content

Commit 3eba187

Browse files
committed
Refactor and remove dead code in mb_ereg(i)_replace
We do not support the 'e' option anymore. Merged together code which would emit an error if this option is present. This also makes it clearer that the whole branch in the replacement section supporting this option is never hit, thus removed.
1 parent beff93f commit 3eba187

File tree

1 file changed

+8
-39
lines changed

1 file changed

+8
-39
lines changed

ext/mbstring/php_mbregex.c

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,8 +1059,12 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
10591059
syntax = MBREX(regex_default_syntax);
10601060
}
10611061
}
1062-
if (eval && !is_callable) {
1063-
php_error_docref(NULL, E_WARNING, "The 'e' option is no longer supported, use mb_ereg_replace_callback instead");
1062+
if (eval) {
1063+
if (is_callable) {
1064+
php_error_docref(NULL, E_WARNING, "Option 'e' cannot be used with replacement callback");
1065+
} else {
1066+
php_error_docref(NULL, E_WARNING, "The 'e' option is no longer supported, use mb_ereg_replace_callback instead");
1067+
}
10641068
RETURN_FALSE;
10651069
}
10661070

@@ -1070,21 +1074,14 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
10701074
RETURN_FALSE;
10711075
}
10721076

1073-
if (eval || is_callable) {
1077+
if (is_callable) {
10741078
pbuf = &eval_buf;
10751079
description = zend_make_compiled_string_description("mbregex replace");
10761080
} else {
10771081
pbuf = &out_buf;
10781082
description = NULL;
10791083
}
10801084

1081-
if (is_callable) {
1082-
if (eval) {
1083-
php_error_docref(NULL, E_WARNING, "Option 'e' cannot be used with replacement callback");
1084-
RETURN_FALSE;
1085-
}
1086-
}
1087-
10881085
/* do the actual work */
10891086
err = 0;
10901087
pos = (OnigUChar *)string;
@@ -1106,35 +1103,7 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
11061103
mb_regex_substitute(pbuf, string, string_len, replace, replace_len, re, regs, enc);
11071104
}
11081105

1109-
if (eval) {
1110-
zval v;
1111-
zend_string *eval_str;
1112-
/* null terminate buffer */
1113-
smart_str_0(&eval_buf);
1114-
1115-
if (eval_buf.s) {
1116-
eval_str = eval_buf.s;
1117-
} else {
1118-
eval_str = ZSTR_EMPTY_ALLOC();
1119-
}
1120-
1121-
/* do eval */
1122-
if (zend_eval_stringl(ZSTR_VAL(eval_str), ZSTR_LEN(eval_str), &v, description) == FAILURE) {
1123-
efree(description);
1124-
zend_throw_error(NULL, "Failed evaluating code: %s%s", PHP_EOL, ZSTR_VAL(eval_str));
1125-
onig_region_free(regs, 1);
1126-
smart_str_free(&out_buf);
1127-
smart_str_free(&eval_buf);
1128-
RETURN_FALSE;
1129-
}
1130-
1131-
/* result of eval */
1132-
convert_to_string(&v);
1133-
smart_str_appendl(&out_buf, Z_STRVAL(v), Z_STRLEN(v));
1134-
/* Clean up */
1135-
smart_str_free(&eval_buf);
1136-
zval_ptr_dtor_str(&v);
1137-
} else if (is_callable) {
1106+
if (is_callable) {
11381107
zval args[1];
11391108
zval subpats, retval;
11401109
int i;

0 commit comments

Comments
 (0)