]> granicus.if.org Git - php/commitdiff
Fix #76999: mb_regex_set_options() return current options
authorChristoph M. Becker <cmbecker69@gmx.de>
Fri, 13 Mar 2020 14:48:53 +0000 (15:48 +0100)
committerChristoph M. Becker <cmbecker69@gmx.de>
Fri, 27 Mar 2020 09:34:16 +0000 (10:34 +0100)
When setting new options, `mb_regex_set_options()` is supposed to
return the *previous* options.

NEWS
ext/mbstring/php_mbregex.c
ext/mbstring/tests/bug76999.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index c05493cc84677ace7a0d3202f37ffd6a142c4529..83ef93e59dec6abe43b162a5f5af61dfc114917e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -56,6 +56,7 @@ PHP                                                                        NEWS
   . Removed deprecated ldap_sort. (mcmic)
 
 - MBString:
+  . Fixed bug #76999 (mb_regex_set_options() return current options). (cmb)
   . Removed the unused $is_hex parameter from mb_decode_numericentity(). (cmb)
 
 - MySQLi:
index ceda96398ea65120450654bb6da545cbb2993a61..bcdff2c4c9540991a74bc0f21808c84882cbf9e5 100644 (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 */
 PHP_FUNCTION(mb_regex_set_options)
 {
-       OnigOptionType opt;
-       OnigSyntaxType *syntax;
+       OnigOptionType opt, prev_opt;
+       OnigSyntaxType *syntax, *prev_syntax;
        char *string = NULL;
        size_t string_len;
        char buf[16];
@@ -1696,7 +1696,9 @@ PHP_FUNCTION(mb_regex_set_options)
                opt = 0;
                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 {
                opt = MBREX(regex_default_options);
                syntax = MBREX(regex_default_syntax);
diff --git a/ext/mbstring/tests/bug76999.phpt b/ext/mbstring/tests/bug76999.phpt
new file mode 100644 (file)
index 0000000..5ba9f0e
--- /dev/null
@@ -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"