Skip to content

Commit 9e77d5a

Browse files
committed
Fix #76999: mb_regex_set_options() return current options
When setting new options, `mb_regex_set_options()` is supposed to return the *previous* options.
1 parent 150df5b commit 9e77d5a

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ PHP NEWS
5656
. Removed deprecated ldap_sort. (mcmic)
5757

5858
- MBString:
59+
. Fixed bug #76999 (mb_regex_set_options() return current options). (cmb)
5960
. Removed the unused $is_hex parameter from mb_decode_numericentity(). (cmb)
6061

6162
- MySQLi:

ext/mbstring/php_mbregex.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -1682,8 +1682,8 @@ static void _php_mb_regex_set_options(OnigOptionType options, OnigSyntaxType *sy
16821682
Set or get the default options for mbregex functions */
16831683
PHP_FUNCTION(mb_regex_set_options)
16841684
{
1685-
OnigOptionType opt;
1686-
OnigSyntaxType *syntax;
1685+
OnigOptionType opt, prev_opt;
1686+
OnigSyntaxType *syntax, *prev_syntax;
16871687
char *string = NULL;
16881688
size_t string_len;
16891689
char buf[16];
@@ -1696,7 +1696,9 @@ PHP_FUNCTION(mb_regex_set_options)
16961696
opt = 0;
16971697
syntax = NULL;
16981698
_php_mb_regex_init_options(string, string_len, &opt, &syntax, NULL);
1699-
_php_mb_regex_set_options(opt, syntax, NULL, NULL);
1699+
_php_mb_regex_set_options(opt, syntax, &prev_opt, &prev_syntax);
1700+
opt = prev_opt;
1701+
syntax = prev_syntax;
17001702
} else {
17011703
opt = MBREX(regex_default_options);
17021704
syntax = MBREX(regex_default_syntax);

ext/mbstring/tests/bug76999.phpt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Bug #76999 (mb_regex_set_options() return current options)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('mbstring')) die('skip mbstring extension not available');
6+
if (!function_exists('mb_regex_set_options')) die('skip mb_regex_set_options() not available');
7+
?>
8+
--FILE--
9+
<?php
10+
mb_regex_set_options("pr");
11+
var_dump(mb_regex_set_options("m"));
12+
var_dump(mb_regex_set_options("mdi"));
13+
var_dump(mb_regex_set_options("m"));
14+
var_dump(mb_regex_set_options("a"));
15+
var_dump(mb_regex_set_options());
16+
?>
17+
--EXPECT--
18+
string(2) "pr"
19+
string(2) "mr"
20+
string(3) "imd"
21+
string(2) "mr"
22+
string(1) "r"

0 commit comments

Comments
 (0)