Skip to content

Commit

Permalink
pcre: Stop special-casing /e (#12355)
Browse files Browse the repository at this point in the history
Support for /e was removed in PHP 7.0, remove the custom error message and stop
special casing it to simplify the logic.
  • Loading branch information
TimWolla authored Oct 6, 2023
1 parent 5cc6979 commit 72cac39
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 20 deletions.
16 changes: 1 addition & 15 deletions ext/pcre/php_pcre.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
#define PREG_SPLIT_DELIM_CAPTURE (1<<1)
#define PREG_SPLIT_OFFSET_CAPTURE (1<<2)

#define PREG_REPLACE_EVAL (1<<0)

#define PREG_GREP_INVERT (1<<0)

#define PREG_JIT (1<<3)
Expand Down Expand Up @@ -737,14 +735,12 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, in
break;
case 'J': coptions |= PCRE2_DUPNAMES; break;

/* Custom preg options */
case 'e': poptions |= PREG_REPLACE_EVAL; break;

case ' ':
case '\n':
case '\r':
break;

case 'e': /* legacy eval */
default:
if (pp[-1]) {
php_error_docref(NULL, E_WARNING, "Unknown modifier '%c'", pp[-1]);
Expand All @@ -760,16 +756,6 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, in
}
}

if (poptions & PREG_REPLACE_EVAL) {
php_error_docref(NULL, E_WARNING, "The /e modifier is no longer supported, use preg_replace_callback instead");
pcre_handle_exec_error(PCRE2_ERROR_INTERNAL);
efree(pattern);
if (key != regex) {
zend_string_release_ex(key, 0);
}
return NULL;
}

if (key != regex) {
tables = (uint8_t *)zend_hash_find_ptr(&char_tables, BG(ctype_string));
if (!tables) {
Expand Down
2 changes: 1 addition & 1 deletion ext/pcre/tests/002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ string(12) "a${1b${1c${1"
Warning: preg_replace(): Compilation failed: missing terminating ] for character class at offset 8 in %s002.php on line %d
NULL

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in %s on line %d
Warning: preg_replace(): Unknown modifier 'e' in %s on line %d
NULL
4 changes: 0 additions & 4 deletions ext/pcre/tests/null_bytes.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ var_dump(preg_match("[abc\0def]", "abc"));
var_dump(preg_match("[abc\0def]", "abc\0def"));
var_dump(preg_match("[abc\0def]", "abc\0fed"));

preg_replace("/foo/e\0/i", "echo('Eek');", "");

?>
--EXPECTF--
Warning: preg_match(): Delimiter must not be alphanumeric, backslash, or NUL in %snull_bytes.php on line 3
Expand Down Expand Up @@ -62,5 +60,3 @@ int(0)
int(0)
int(1)
int(0)

Warning: preg_replace(): NUL is not a valid modifier in %snull_bytes.php on line 27

0 comments on commit 72cac39

Please sign in to comment.