Skip to content

Commit 76c687f

Browse files
committed
Fixed bug #77428
mb_ereg_replace historically has not supported escaping backslashes with backslashes. Go back to that behavior for BC reasons.
1 parent 7f8cab2 commit 76c687f

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ PHP NEWS
3535
. Fixed bug #77385 (buffer overflow in fetch_token). (Stas)
3636
. Fixed bug #77394 (Buffer overflow in multibyte case folding - unicode). (Stas)
3737
. Fixed bug #77418 (Heap overflow in utf32be_mbc_to_code). (Stas)
38+
. Fixed bug #77428 (mb_ereg_replace() doesn't replace a substitution
39+
variable). (Nikita)
3840

3941
- MySQLnd:
4042
. Fixed bug #75684 (In mysqlnd_ext_plugin.h the plugin methods family has

ext/mbstring/php_mbregex.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,9 @@ static inline void mb_regex_substitute(
791791
no = onig_name_to_backref_number(regexp, (OnigUChar *)name, (OnigUChar *)name_end, regs);
792792
break;
793793
default:
794-
p += clen;
794+
/* We're not treating \ as an escape character and will interpret something like
795+
* \\1 as \ followed by \1, rather than \\ followed by 1. This is because this
796+
* function has not supported escaping of backslashes historically. */
795797
smart_str_appendl(pbuf, sp, p - sp);
796798
continue;
797799
}

ext/mbstring/tests/bug77428.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #77428: mb_ereg_replace() doesn't replace a substitution variable
3+
--FILE--
4+
<?php
5+
6+
// This behavior is broken, but kept for BC reasons
7+
var_dump(mb_ereg_replace('(%)', '\\\1', 'a%c'));
8+
// For clarify, the above line is equivalent to:
9+
var_dump(mb_ereg_replace('(%)', '\\\\1', 'a%c'));
10+
11+
?>
12+
--EXPECT--
13+
string(4) "a\%c"
14+
string(4) "a\%c"

0 commit comments

Comments
 (0)