php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #64730
Patch second_arg_rege_key.patch revision 2013-05-04 12:35 UTC by laruence@php.net
Patch sencode_argument.patch revision 2013-04-29 16:30 UTC by laruence@php.net

Patch sencode_argument.patch for Regexps related Bug #64730

Patch version 2013-04-29 16:30 UTC

Return to Bug #64730 | Download this patch
Patch Revisions:

Developer: laruence@php.net

diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c
index 7d34d9f..0a12595 100644
--- a/ext/pcre/php_pcre.c
+++ b/ext/pcre/php_pcre.c
@@ -855,11 +855,12 @@ static int preg_get_backref(char **str, int *backref)
 
 /* {{{ preg_do_repl_func
  */
-static int preg_do_repl_func(zval *function, char *subject, int *offsets, char **subpat_names, int count, char **result TSRMLS_DC)
+static int preg_do_repl_func(zval *function, char *regex, int regex_len, char *subject, int *offsets, char **subpat_names, int count, char **result TSRMLS_DC)
 {
 	zval		*retval_ptr;		/* Function return value */
-	zval	   **args[1];			/* Argument to pass to function */
+	zval	   **args[2];			/* Argument to pass to function */
 	zval		*subpats;			/* Captured subpatterns */ 
+	zval        *pattern;
 	int			 result_len;		/* Return value length */
 	int			 i;
 
@@ -871,9 +872,17 @@ static int preg_do_repl_func(zval *function, char *subject, int *offsets, char *
 		}
 		add_next_index_stringl(subpats, &subject[offsets[i<<1]], offsets[(i<<1)+1] - offsets[i<<1], 1);
 	}
+	MAKE_STD_ZVAL(pattern);
+	if (regex_len) {
+		ZVAL_STRINGL(pattern, regex, regex_len, 1);
+	} else {
+		ZVAL_NULL(pattern);
+	}
+
 	args[0] = &subpats;
+	args[1] = &pattern;
 
-	if (call_user_function_ex(EG(function_table), NULL, function, &retval_ptr, 1, args, 0, NULL TSRMLS_CC) == SUCCESS && retval_ptr) {
+	if (call_user_function_ex(EG(function_table), NULL, function, &retval_ptr, 2, args, 0, NULL TSRMLS_CC) == SUCCESS && retval_ptr) {
 		convert_to_string_ex(&retval_ptr);
 		*result = estrndup(Z_STRVAL_P(retval_ptr), Z_STRLEN_P(retval_ptr));
 		result_len = Z_STRLEN_P(retval_ptr);
@@ -887,6 +896,7 @@ static int preg_do_repl_func(zval *function, char *subject, int *offsets, char *
 	}
 
 	zval_ptr_dtor(&subpats);
+	zval_ptr_dtor(&pattern);
 
 	return result_len;
 }
@@ -994,14 +1004,21 @@ PHPAPI char *php_pcre_replace(char *regex,   int regex_len,
 		return NULL;
 	}
 
-	return php_pcre_replace_impl(pce, subject, subject_len, replace_val, 
-		is_callable_replace, result_len, limit, replace_count TSRMLS_CC);
+	return php_pcre_replace_impl_ex(pce, subject, subject_len, replace_val, 
+		is_callable_replace, result_len, limit, replace_count, regex, regex_len TSRMLS_CC);
 }
 /* }}} */
 
-/* {{{ php_pcre_replace_impl() */
+/* {{{ php_pcre_replace_impl */
 PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, int subject_len, zval *replace_val, 
-	int is_callable_replace, int *result_len, int limit, int *replace_count TSRMLS_DC)
+	int is_callable_replace, int *result_len, int limit, int *replace_count TSRMLS_DC) {
+	return php_pcre_replace_impl_ex(pce, subject, subject_len, replace_val, is_callable_replace, result_len, limit, replace_count, NULL, 0 TSRMLS_CC);
+}
+/* }}} */
+
+/* {{{ php_pcre_replace_impl_ex() */
+PHPAPI char *php_pcre_replace_impl_ex(pcre_cache_entry *pce, char *subject, int subject_len, zval *replace_val, 
+	int is_callable_replace, int *result_len, int limit, int *replace_count, char *regex, int regex_len TSRMLS_DC)
 {
 	pcre_extra		*extra = pce->extra;/* Holds results of studying */
 	pcre_extra		 extra_data;		/* Used locally for exec options */
@@ -1118,7 +1135,7 @@ PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, int sub
 				new_len += eval_result_len;
 			} else if (is_callable_replace) {
 				/* Use custom function to get replacement string and its length. */
-				eval_result_len = preg_do_repl_func(replace_val, subject, offsets, subpat_names, count, &eval_result TSRMLS_CC);
+				eval_result_len = preg_do_repl_func(replace_val, regex, regex_len, subject, offsets, subpat_names, count, &eval_result TSRMLS_CC);
 				new_len += eval_result_len;
 			} else { /* do regular substitution */
 				walk = replace;
diff --git a/ext/pcre/php_pcre.h b/ext/pcre/php_pcre.h
index db14ce3..17d5170 100644
--- a/ext/pcre/php_pcre.h
+++ b/ext/pcre/php_pcre.h
@@ -57,8 +57,10 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, int regex_le
 PHPAPI void  php_pcre_match_impl(  pcre_cache_entry *pce, char *subject, int subject_len, zval *return_value,
 	zval *subpats, int global, int use_flags, long flags, long start_offset TSRMLS_DC);
 
-PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, int subject_len, zval *return_value, 
-	int is_callable_replace, int *result_len, int limit, int *replace_count TSRMLS_DC);
+PHPAPI char *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject, int subject_len, zval *return_value,
+		    int is_callable_replace, int *result_len, int limit, int *replace_count TSRMLS_DC);
+PHPAPI char *php_pcre_replace_impl_ex(pcre_cache_entry *pce, char *subject, int subject_len, zval *return_value, 
+	int is_callable_replace, int *result_len, int limit, int *replace_count, char *regex, int regex_len TSRMLS_DC);
 
 PHPAPI void  php_pcre_split_impl(  pcre_cache_entry *pce, char *subject, int subject_len, zval *return_value,
 	long limit_val, long flags TSRMLS_DC);
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 05 16:01:30 2024 UTC