Skip to content

Commit 29f942b

Browse files
committed
Move "/e" modifier check into regex compiler
1 parent 5d60651 commit 29f942b

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

ext/pcre/php_pcre.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,18 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(zend_string *regex)
715715
}
716716
}
717717

718+
if (poptions & PREG_REPLACE_EVAL) {
719+
php_error_docref(NULL, E_WARNING, "The /e modifier is no longer supported, use preg_replace_callback instead");
720+
pcre_handle_exec_error(PCRE2_ERROR_INTERNAL);
721+
efree(pattern);
722+
#if HAVE_SETLOCALE
723+
if (key != regex) {
724+
zend_string_release_ex(key, 0);
725+
}
726+
#endif
727+
return NULL;
728+
}
729+
718730
#if HAVE_SETLOCALE
719731
if (key != regex) {
720732
tables = (uint8_t *)zend_hash_find_ptr(&char_tables, BG(locale_string));
@@ -1517,11 +1529,6 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *su
15171529
zend_string *result; /* Result of replacement */
15181530
pcre2_match_data *match_data;
15191531

1520-
if (UNEXPECTED(pce->preg_options & PREG_REPLACE_EVAL)) {
1521-
php_error_docref(NULL, E_WARNING, "The /e modifier is no longer supported, use preg_replace_callback instead");
1522-
return NULL;
1523-
}
1524-
15251532
/* Calculate the size of the offsets array, and allocate memory for it. */
15261533
num_subpats = pce->capture_count + 1;
15271534

@@ -1760,11 +1767,6 @@ static zend_string *php_pcre_replace_func_impl(pcre_cache_entry *pce, zend_strin
17601767
pcre2_match_data *match_data;
17611768
zend_bool old_mdata_used;
17621769

1763-
if (UNEXPECTED(pce->preg_options & PREG_REPLACE_EVAL)) {
1764-
php_error_docref(NULL, E_WARNING, "The /e modifier is no longer supported, use preg_replace_callback instead");
1765-
return NULL;
1766-
}
1767-
17681770
/* Calculate the size of the offsets array, and allocate memory for it. */
17691771
num_subpats = pce->capture_count + 1;
17701772

0 commit comments

Comments
 (0)