Skip to content

Commit 72cac39

Browse files
authored
pcre: Stop special-casing /e (#12355)
Support for /e was removed in PHP 7.0, remove the custom error message and stop special casing it to simplify the logic.
1 parent 5cc6979 commit 72cac39

File tree

3 files changed

+2
-20
lines changed

3 files changed

+2
-20
lines changed

ext/pcre/php_pcre.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
#define PREG_SPLIT_DELIM_CAPTURE (1<<1)
3535
#define PREG_SPLIT_OFFSET_CAPTURE (1<<2)
3636

37-
#define PREG_REPLACE_EVAL (1<<0)
38-
3937
#define PREG_GREP_INVERT (1<<0)
4038

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

740-
/* Custom preg options */
741-
case 'e': poptions |= PREG_REPLACE_EVAL; break;
742-
743738
case ' ':
744739
case '\n':
745740
case '\r':
746741
break;
747742

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

763-
if (poptions & PREG_REPLACE_EVAL) {
764-
php_error_docref(NULL, E_WARNING, "The /e modifier is no longer supported, use preg_replace_callback instead");
765-
pcre_handle_exec_error(PCRE2_ERROR_INTERNAL);
766-
efree(pattern);
767-
if (key != regex) {
768-
zend_string_release_ex(key, 0);
769-
}
770-
return NULL;
771-
}
772-
773759
if (key != regex) {
774760
tables = (uint8_t *)zend_hash_find_ptr(&char_tables, BG(ctype_string));
775761
if (!tables) {

ext/pcre/tests/002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ string(12) "a${1b${1c${1"
2424
Warning: preg_replace(): Compilation failed: missing terminating ] for character class at offset 8 in %s002.php on line %d
2525
NULL
2626

27-
Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in %s on line %d
27+
Warning: preg_replace(): Unknown modifier 'e' in %s on line %d
2828
NULL

ext/pcre/tests/null_bytes.phpt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ var_dump(preg_match("[abc\0def]", "abc"));
2727
var_dump(preg_match("[abc\0def]", "abc\0def"));
2828
var_dump(preg_match("[abc\0def]", "abc\0fed"));
2929

30-
preg_replace("/foo/e\0/i", "echo('Eek');", "");
31-
3230
?>
3331
--EXPECTF--
3432
Warning: preg_match(): Delimiter must not be alphanumeric, backslash, or NUL in %snull_bytes.php on line 3
@@ -62,5 +60,3 @@ int(0)
6260
int(0)
6361
int(1)
6462
int(0)
65-
66-
Warning: preg_replace(): NUL is not a valid modifier in %snull_bytes.php on line 27

0 commit comments

Comments
 (0)