Skip to content

Commit 4a4c68d

Browse files
committed
Make mb_ereg(i) argument a normal string argument
Instead of manually handling the string conversion, use the standard zpp mechanism.
1 parent 06ed6b8 commit 4a4c68d

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

ext/mbstring/php_mbregex.c

+6-16
Original file line numberDiff line numberDiff line change
@@ -853,16 +853,16 @@ PHP_FUNCTION(mb_regex_encoding)
853853
/* {{{ _php_mb_regex_ereg_exec */
854854
static void _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase)
855855
{
856-
zval *arg_pattern, *array = NULL;
857-
char *string;
858-
size_t string_len;
856+
zval *array = NULL;
857+
char *arg_pattern, *string;
858+
size_t arg_pattern_len, string_len;
859859
php_mb_regex_t *re;
860860
OnigRegion *regs = NULL;
861861
int i, match_len, beg, end;
862862
OnigOptionType options;
863863
char *str;
864864

865-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "zs|z", &arg_pattern, &string, &string_len, &array) == FAILURE) {
865+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|z", &arg_pattern, &arg_pattern_len, &string, &string_len, &array) == FAILURE) {
866866
RETURN_FALSE;
867867
}
868868

@@ -886,23 +886,13 @@ static void _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase)
886886
options |= ONIG_OPTION_IGNORECASE;
887887
}
888888

889-
/* compile the regular expression from the supplied regex */
890-
if (Z_TYPE_P(arg_pattern) != IS_STRING) {
891-
/* we convert numbers to integers and treat them as a string */
892-
if (Z_TYPE_P(arg_pattern) == IS_DOUBLE) {
893-
convert_to_long_ex(arg_pattern); /* get rid of decimal places */
894-
}
895-
convert_to_string_ex(arg_pattern);
896-
/* don't bother doing an extended regex with just a number */
897-
}
898-
899-
if (Z_STRLEN_P(arg_pattern) == 0) {
889+
if (arg_pattern_len == 0) {
900890
php_error_docref(NULL, E_WARNING, "empty pattern");
901891
RETVAL_FALSE;
902892
goto out;
903893
}
904894

905-
re = php_mbregex_compile_pattern(Z_STRVAL_P(arg_pattern), Z_STRLEN_P(arg_pattern), options, MBREX(current_mbctype), MBREX(regex_default_syntax));
895+
re = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len, options, MBREX(current_mbctype), MBREX(regex_default_syntax));
906896
if (re == NULL) {
907897
RETVAL_FALSE;
908898
goto out;

ext/mbstring/tests/mb_ereg1.phpt

+2-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ array(3) {
4343
}
4444
}
4545

46-
Notice: Array to string conversion in %s on line %d
46+
Warning: mb_ereg() expects parameter 1 to be string, array given in %s on line %d
4747
bool(false)
4848
array(3) {
4949
[0]=>
@@ -52,8 +52,7 @@ array(3) {
5252
[1]=>
5353
int(1)
5454
[2]=>
55-
array(0) {
56-
}
55+
string(0) ""
5756
}
5857

5958
Warning: mb_ereg() expects parameter 2 to be string, array given in %s on line %d

ext/mbstring/tests/mb_ereg_variation1.phpt

+4-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fclose($fp);
8989

9090
echo "Done";
9191
?>
92-
--EXPECT--
92+
--EXPECTF--
9393
*** Testing mb_ereg() : usage variations ***
9494

9595
-- Iteration 1 --
@@ -172,7 +172,8 @@ array(0) {
172172
}
173173

174174
-- Iteration 16 --
175+
176+
Warning: mb_ereg() expects parameter 1 to be string, resource given in %s on line %d
175177
bool(false)
176-
array(0) {
177-
}
178+
NULL
178179
Done

0 commit comments

Comments
 (0)