summaryrefslogtreecommitdiff
path: root/ext/mbstring/php_mbregex.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/mbstring/php_mbregex.c')
-rw-r--r--ext/mbstring/php_mbregex.c93
1 files changed, 33 insertions, 60 deletions
diff --git a/ext/mbstring/php_mbregex.c b/ext/mbstring/php_mbregex.c
index 11f63858b2..d7c236fd4a 100644
--- a/ext/mbstring/php_mbregex.c
+++ b/ext/mbstring/php_mbregex.c
@@ -1,7 +1,5 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 7 |
- +----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
@@ -841,7 +839,7 @@ PHP_FUNCTION(mb_regex_encoding)
OnigEncoding mbctype;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &encoding, &encoding_len) == FAILURE) {
- return;
+ RETURN_THROWS();
}
if (!encoding) {
@@ -889,23 +887,23 @@ static int _php_mb_onig_search(regex_t* reg, const OnigUChar* str, const OnigUCh
/* {{{ _php_mb_regex_ereg_exec */
static void _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase)
{
- zval *arg_pattern, *array = NULL;
- char *string;
- size_t string_len;
+ zval *array = NULL;
+ char *arg_pattern, *string;
+ size_t arg_pattern_len, string_len;
php_mb_regex_t *re;
OnigRegion *regs = NULL;
int i, match_len, beg, end;
OnigOptionType options;
char *str;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "zs|z", &arg_pattern, &string, &string_len, &array) == FAILURE) {
- RETURN_FALSE;
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|z", &arg_pattern, &arg_pattern_len, &string, &string_len, &array) == FAILURE) {
+ RETURN_THROWS();
}
if (array != NULL) {
array = zend_try_array_init(array);
if (!array) {
- return;
+ RETURN_THROWS();
}
}
@@ -922,25 +920,13 @@ static void _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase)
options |= ONIG_OPTION_IGNORECASE;
}
- /* compile the regular expression from the supplied regex */
- if (Z_TYPE_P(arg_pattern) != IS_STRING) {
- /* we convert numbers to integers and treat them as a string */
- if (Z_TYPE_P(arg_pattern) == IS_DOUBLE) {
- convert_to_long_ex(arg_pattern); /* get rid of decimal places */
- }
- if (!try_convert_to_string(arg_pattern)) {
- return;
- }
- /* don't bother doing an extended regex with just a number */
- }
-
- if (Z_STRLEN_P(arg_pattern) == 0) {
- php_error_docref(NULL, E_WARNING, "empty pattern");
+ if (arg_pattern_len == 0) {
+ php_error_docref(NULL, E_WARNING, "Empty pattern");
RETVAL_FALSE;
goto out;
}
- re = php_mbregex_compile_pattern(Z_STRVAL_P(arg_pattern), Z_STRLEN_P(arg_pattern), options, MBREX(current_mbctype), MBREX(regex_default_syntax));
+ re = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len, options, MBREX(current_mbctype), MBREX(regex_default_syntax));
if (re == NULL) {
RETVAL_FALSE;
goto out;
@@ -1005,8 +991,6 @@ PHP_FUNCTION(mb_eregi)
/* {{{ _php_mb_regex_ereg_replace_exec */
static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOptionType options, int is_callable)
{
- zval *arg_pattern_zval;
-
char *arg_pattern;
size_t arg_pattern_len;
@@ -1029,7 +1013,6 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
OnigUChar *pos;
OnigUChar *string_lim;
char *description = NULL;
- char pat_buf[6];
const mbfl_encoding *enc;
@@ -1048,20 +1031,20 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
size_t option_str_len = 0;
if (!is_callable) {
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "zss|s",
- &arg_pattern_zval,
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "sss|s",
+ &arg_pattern, &arg_pattern_len,
&replace, &replace_len,
&string, &string_len,
&option_str, &option_str_len) == FAILURE) {
- RETURN_FALSE;
+ RETURN_THROWS();
}
} else {
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "zfs|s",
- &arg_pattern_zval,
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "sfs|s",
+ &arg_pattern, &arg_pattern_len,
&arg_replace_fci, &arg_replace_fci_cache,
&string, &string_len,
&option_str, &option_str_len) == FAILURE) {
- RETURN_FALSE;
+ RETURN_THROWS();
}
}
@@ -1081,28 +1064,10 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
}
}
if (eval && !is_callable) {
- php_error_docref(NULL, E_DEPRECATED, "The 'e' option is deprecated, use mb_ereg_replace_callback instead");
- }
- if (Z_TYPE_P(arg_pattern_zval) == IS_STRING) {
- arg_pattern = Z_STRVAL_P(arg_pattern_zval);
- arg_pattern_len = Z_STRLEN_P(arg_pattern_zval);
- } else {
- php_error_docref(NULL, E_DEPRECATED,
- "Non-string patterns will be interpreted as strings in the future. "
- "Use an explicit chr() call to preserve the current behavior");
-
- /* FIXME: this code is not multibyte aware! */
- convert_to_long_ex(arg_pattern_zval);
- pat_buf[0] = (char)Z_LVAL_P(arg_pattern_zval);
- pat_buf[1] = '\0';
- pat_buf[2] = '\0';
- pat_buf[3] = '\0';
- pat_buf[4] = '\0';
- pat_buf[5] = '\0';
-
- arg_pattern = pat_buf;
- arg_pattern_len = 1;
+ php_error_docref(NULL, E_WARNING, "The 'e' option is no longer supported, use mb_ereg_replace_callback instead");
+ RETURN_FALSE;
}
+
/* create regex pattern buffer */
re = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len, options, MBREX(current_mbctype), syntax);
if (re == NULL) {
@@ -1286,7 +1251,7 @@ PHP_FUNCTION(mb_split)
zend_long count = -1;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l", &arg_pattern, &arg_pattern_len, &string, &string_len, &count) == FAILURE) {
- RETURN_FALSE;
+ RETURN_THROWS();
}
if (count > 0) {
@@ -1377,7 +1342,7 @@ PHP_FUNCTION(mb_ereg_match)
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|s",
&arg_pattern, &arg_pattern_len, &string, &string_len,
&option_str, &option_str_len)==FAILURE) {
- RETURN_FALSE;
+ RETURN_THROWS();
}
if (option_str != NULL) {
@@ -1430,7 +1395,7 @@ _php_mb_regex_ereg_search_exec(INTERNAL_FUNCTION_PARAMETERS, int mode)
OnigSyntaxType *syntax;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|ss", &arg_pattern, &arg_pattern_len, &arg_options, &arg_options_len) == FAILURE) {
- return;
+ RETURN_THROWS();
}
option = MBREX(regex_default_options);
@@ -1567,7 +1532,7 @@ PHP_FUNCTION(mb_ereg_search_init)
OnigOptionType option;
if (zend_parse_parameters(argc, "S|ss", &arg_str, &arg_pattern, &arg_pattern_len, &arg_options, &arg_options_len) == FAILURE) {
- return;
+ RETURN_THROWS();
}
if (argc > 1 && arg_pattern_len == 0) {
@@ -1622,6 +1587,10 @@ PHP_FUNCTION(mb_ereg_search_getregs)
size_t n, i, len, beg, end;
OnigUChar *str;
+ if (zend_parse_parameters_none() == FAILURE) {
+ RETURN_THROWS();
+ }
+
if (MBREX(search_regs) != NULL && Z_TYPE(MBREX(search_str)) == IS_STRING) {
array_init(return_value);
@@ -1656,6 +1625,10 @@ PHP_FUNCTION(mb_ereg_search_getregs)
Get search start position */
PHP_FUNCTION(mb_ereg_search_getpos)
{
+ if (zend_parse_parameters_none() == FAILURE) {
+ RETURN_THROWS();
+ }
+
RETVAL_LONG(MBREX(search_pos));
}
/* }}} */
@@ -1667,7 +1640,7 @@ PHP_FUNCTION(mb_ereg_search_setpos)
zend_long position;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &position) == FAILURE) {
- return;
+ RETURN_THROWS();
}
/* Accept negative position if length of search string can be determined */
@@ -1712,7 +1685,7 @@ PHP_FUNCTION(mb_regex_set_options)
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s",
&string, &string_len) == FAILURE) {
- RETURN_FALSE;
+ RETURN_THROWS();
}
if (string != NULL) {
opt = 0;