Fix #76999: mb_regex_set_options() return current options

When setting new options, `mb_regex_set_options()` is supposed to
return the *previous* options.
This commit is contained in:
Christoph M. Becker 2020-03-13 15:48:53 +01:00
parent 150df5b17c
commit 9e77d5a9da
3 changed files with 28 additions and 3 deletions

1
NEWS
View file

@ -56,6 +56,7 @@ PHP NEWS
. Removed deprecated ldap_sort. (mcmic) . Removed deprecated ldap_sort. (mcmic)
- MBString: - MBString:
. Fixed bug #76999 (mb_regex_set_options() return current options). (cmb)
. Removed the unused $is_hex parameter from mb_decode_numericentity(). (cmb) . Removed the unused $is_hex parameter from mb_decode_numericentity(). (cmb)
- MySQLi: - MySQLi:

View file

@ -1682,8 +1682,8 @@ static void _php_mb_regex_set_options(OnigOptionType options, OnigSyntaxType *sy
Set or get the default options for mbregex functions */ Set or get the default options for mbregex functions */
PHP_FUNCTION(mb_regex_set_options) PHP_FUNCTION(mb_regex_set_options)
{ {
OnigOptionType opt; OnigOptionType opt, prev_opt;
OnigSyntaxType *syntax; OnigSyntaxType *syntax, *prev_syntax;
char *string = NULL; char *string = NULL;
size_t string_len; size_t string_len;
char buf[16]; char buf[16];
@ -1696,7 +1696,9 @@ PHP_FUNCTION(mb_regex_set_options)
opt = 0; opt = 0;
syntax = NULL; syntax = NULL;
_php_mb_regex_init_options(string, string_len, &opt, &syntax, NULL); _php_mb_regex_init_options(string, string_len, &opt, &syntax, NULL);
_php_mb_regex_set_options(opt, syntax, NULL, NULL); _php_mb_regex_set_options(opt, syntax, &prev_opt, &prev_syntax);
opt = prev_opt;
syntax = prev_syntax;
} else { } else {
opt = MBREX(regex_default_options); opt = MBREX(regex_default_options);
syntax = MBREX(regex_default_syntax); syntax = MBREX(regex_default_syntax);

View file

@ -0,0 +1,22 @@
--TEST--
Bug #76999 (mb_regex_set_options() return current options)
--SKIPIF--
<?php
if (!extension_loaded('mbstring')) die('skip mbstring extension not available');
if (!function_exists('mb_regex_set_options')) die('skip mb_regex_set_options() not available');
?>
--FILE--
<?php
mb_regex_set_options("pr");
var_dump(mb_regex_set_options("m"));
var_dump(mb_regex_set_options("mdi"));
var_dump(mb_regex_set_options("m"));
var_dump(mb_regex_set_options("a"));
var_dump(mb_regex_set_options());
?>
--EXPECT--
string(2) "pr"
string(2) "mr"
string(3) "imd"
string(2) "mr"
string(1) "r"