@@ -986,88 +986,6 @@ static zend_string *preg_do_repl_func(zval *function, char *subject, int *offset
986
986
}
987
987
/* }}} */
988
988
989
- /* {{{ preg_do_eval
990
- */
991
- static zend_string * preg_do_eval (char * eval_str , int eval_str_len , char * subject ,
992
- int * offsets , int count )
993
- {
994
- zval retval ; /* Return value from evaluation */
995
- char * eval_str_end , /* End of eval string */
996
- * match , /* Current match for a backref */
997
- * walk , /* Used to walk the code string */
998
- * segment , /* Start of segment to append while walking */
999
- walk_last ; /* Last walked character */
1000
- int match_len ; /* Length of the match */
1001
- int backref ; /* Current backref */
1002
- zend_string * esc_match ; /* Quote-escaped match */
1003
- zend_string * result_str ;
1004
- char * compiled_string_description ;
1005
- smart_str code = {0 };
1006
-
1007
- eval_str_end = eval_str + eval_str_len ;
1008
- walk = segment = eval_str ;
1009
- walk_last = 0 ;
1010
-
1011
- while (walk < eval_str_end ) {
1012
- /* If found a backreference.. */
1013
- if ('\\' == * walk || '$' == * walk ) {
1014
- smart_str_appendl (& code , segment , walk - segment );
1015
- if (walk_last == '\\' ) {
1016
- code .s -> val [code .s -> len - 1 ] = * walk ++ ;
1017
- segment = walk ;
1018
- walk_last = 0 ;
1019
- continue ;
1020
- }
1021
- segment = walk ;
1022
- if (preg_get_backref (& walk , & backref )) {
1023
- if (backref < count ) {
1024
- /* Find the corresponding string match and substitute it
1025
- in instead of the backref */
1026
- match = subject + offsets [backref <<1 ];
1027
- match_len = offsets [(backref <<1 )+ 1 ] - offsets [backref <<1 ];
1028
- if (match_len ) {
1029
- esc_match = php_addslashes (zend_string_init (match , match_len , 0 ), 1 );
1030
- } else {
1031
- esc_match = zend_string_init (match , match_len , 0 );
1032
- }
1033
- } else {
1034
- esc_match = STR_EMPTY_ALLOC ();
1035
- }
1036
- smart_str_appendl (& code , esc_match -> val , esc_match -> len );
1037
-
1038
- segment = walk ;
1039
-
1040
- /* Clean up and reassign */
1041
- zend_string_release (esc_match );
1042
- continue ;
1043
- }
1044
- }
1045
- walk ++ ;
1046
- walk_last = walk [-1 ];
1047
- }
1048
- smart_str_appendl (& code , segment , walk - segment );
1049
- smart_str_0 (& code );
1050
-
1051
- compiled_string_description = zend_make_compiled_string_description ("regexp code" );
1052
- /* Run the code */
1053
- if (zend_eval_stringl (code .s -> val , code .s -> len , & retval , compiled_string_description ) == FAILURE ) {
1054
- efree (compiled_string_description );
1055
- php_error_docref (NULL ,E_ERROR , "Failed evaluating code: %s%s" , PHP_EOL , code .s -> val );
1056
- /* zend_error() does not return in this case */
1057
- }
1058
- efree (compiled_string_description );
1059
-
1060
- /* Save the return string */
1061
- result_str = zval_get_string (& retval );
1062
-
1063
- /* Clean up */
1064
- zval_dtor (& retval );
1065
- smart_str_free (& code );
1066
-
1067
- return result_str ;
1068
- }
1069
- /* }}} */
1070
-
1071
989
/* {{{ php_pcre_replace
1072
990
*/
1073
991
PHPAPI zend_string * php_pcre_replace (zend_string * regex ,
@@ -1103,7 +1021,6 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject,
1103
1021
int alloc_len ; /* Actual allocated length */
1104
1022
int match_len ; /* Length of the current match */
1105
1023
int backref ; /* Backreference number */
1106
- int eval ; /* If the replacement string should be eval'ed */
1107
1024
int start_offset ; /* Where the new search starts */
1108
1025
int g_notempty = 0 ; /* If the match should not be empty */
1109
1026
int replace_len = 0 ; /* Length of replacement string */
@@ -1117,7 +1034,7 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject,
1117
1034
int result_len ; /* Length of result */
1118
1035
unsigned char * mark = NULL ; /* Target for MARK name */
1119
1036
zend_string * result ; /* Result of replacement */
1120
- zend_string * eval_result = NULL ; /* Result of eval or custom function */
1037
+ zend_string * eval_result = NULL ; /* Result of custom function */
1121
1038
ALLOCA_FLAG (use_heap );
1122
1039
1123
1040
if (extra == NULL ) {
@@ -1127,22 +1044,16 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject,
1127
1044
extra -> match_limit = (unsigned long )PCRE_G (backtrack_limit );
1128
1045
extra -> match_limit_recursion = (unsigned long )PCRE_G (recursion_limit );
1129
1046
1130
- eval = pce -> preg_options & PREG_REPLACE_EVAL ;
1131
- if (is_callable_replace ) {
1132
- if (eval ) {
1133
- php_error_docref (NULL , E_WARNING , "Modifier /e cannot be used with replacement callback" );
1134
- return NULL ;
1135
- }
1136
- } else {
1047
+ if (pce -> preg_options & PREG_REPLACE_EVAL ) {
1048
+ php_error_docref (NULL TSRMLS_CC , E_WARNING , "The /e modifier is no longer supported, use preg_replace_callback instead" );
1049
+ return NULL ;
1050
+ }
1051
+ if (!is_callable_replace ) {
1137
1052
replace = Z_STRVAL_P (replace_val );
1138
1053
replace_len = (int )Z_STRLEN_P (replace_val );
1139
1054
replace_end = replace + replace_len ;
1140
1055
}
1141
1056
1142
- if (eval ) {
1143
- php_error_docref (NULL , E_DEPRECATED , "The /e modifier is deprecated, use preg_replace_callback instead" );
1144
- }
1145
-
1146
1057
/* Calculate the size of the offsets array, and allocate memory for it. */
1147
1058
num_subpats = pce -> capture_count + 1 ;
1148
1059
size_offsets = num_subpats * 3 ;
@@ -1201,13 +1112,8 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject,
1201
1112
match = subject + offsets [0 ];
1202
1113
1203
1114
new_len = result_len + offsets [0 ] - start_offset ; /* part before the match */
1204
-
1205
- /* If evaluating, do it and add the return string's length */
1206
- if (eval ) {
1207
- eval_result = preg_do_eval (replace , replace_len , subject ,
1208
- offsets , count );
1209
- new_len += (int )eval_result -> len ;
1210
- } else if (is_callable_replace ) {
1115
+
1116
+ if (is_callable_replace ) {
1211
1117
/* Use custom function to get replacement string and its length. */
1212
1118
eval_result = preg_do_repl_func (replace_val , subject , offsets , subpat_names , count , mark );
1213
1119
new_len += (int )eval_result -> len ;
@@ -1243,10 +1149,9 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, char *subject,
1243
1149
1244
1150
/* copy replacement and backrefs */
1245
1151
walkbuf = result -> val + result_len ;
1246
-
1247
- /* If evaluating or using custom function, copy result to the buffer
1248
- * and clean up. */
1249
- if (eval || is_callable_replace ) {
1152
+
1153
+ /* If using custom function, copy result to the buffer and clean up. */
1154
+ if (is_callable_replace ) {
1250
1155
memcpy (walkbuf , eval_result -> val , eval_result -> len );
1251
1156
result_len += (int )eval_result -> len ;
1252
1157
if (eval_result ) zend_string_release (eval_result );
0 commit comments