Skip to content

Commit 3f2f36d

Browse files
committed
Fix non-default syntax in mb_ereg_search()
1 parent 59e343c commit 3f2f36d

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

ext/mbstring/php_mbregex.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,19 +1426,19 @@ _php_mb_regex_ereg_search_exec(INTERNAL_FUNCTION_PARAMETERS, int mode)
14261426
size_t arg_pattern_len, arg_options_len;
14271427
int err;
14281428
size_t n, i, pos, len, beg, end;
1429-
OnigOptionType option;
1429+
OnigOptionType option = 0;
14301430
OnigUChar *str;
14311431
OnigSyntaxType *syntax;
14321432

14331433
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|ss", &arg_pattern, &arg_pattern_len, &arg_options, &arg_options_len) == FAILURE) {
14341434
return;
14351435
}
14361436

1437-
option = MBREX(regex_default_options);
1438-
14391437
if (arg_options) {
1440-
option = 0;
14411438
_php_mb_regex_init_options(arg_options, arg_options_len, &option, &syntax, NULL);
1439+
} else {
1440+
option |= MBREX(regex_default_options);
1441+
syntax = MBREX(regex_default_syntax);
14421442
}
14431443

14441444
if (MBREX(search_regs)) {
@@ -1448,7 +1448,7 @@ _php_mb_regex_ereg_search_exec(INTERNAL_FUNCTION_PARAMETERS, int mode)
14481448

14491449
if (arg_pattern) {
14501450
/* create regex pattern buffer */
1451-
if ((MBREX(search_re) = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len, option, MBREX(current_mbctype), MBREX(regex_default_syntax))) == NULL) {
1451+
if ((MBREX(search_re) = php_mbregex_compile_pattern(arg_pattern, arg_pattern_len, option, MBREX(current_mbctype), syntax)) == NULL) {
14521452
RETURN_FALSE;
14531453
}
14541454
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
Specifying non-default syntax in mb_ereg_search()
3+
--FILE--
4+
<?php
5+
6+
mb_ereg_search_init("a");
7+
var_dump(mb_ereg_search("a\\{1,2\\}", "b"));
8+
9+
?>
10+
--EXPECT--
11+
bool(true)

0 commit comments

Comments
 (0)