Skip to content

Normalize mb_ereg() return value #6331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/mbstring/mbstring.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ function mb_chr(int $codepoint, ?string $encoding = null): string|false {}
function mb_regex_encoding(?string $encoding = null): string|bool {}

/** @param array $matches */
function mb_ereg(string $pattern, string $string, &$matches = null): int|false {}
function mb_ereg(string $pattern, string $string, &$matches = null): bool {}

/** @param array $matches */
function mb_eregi(string $pattern, string $string, &$matches = null): int|false {}
function mb_eregi(string $pattern, string $string, &$matches = null): bool {}

function mb_ereg_replace(string $pattern, string $replacement, string $string, ?string $options = null): string|false|null {}

Expand Down
4 changes: 2 additions & 2 deletions ext/mbstring/mbstring_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 3e5b45cf71fe75bde026062816cb28eceea4aa38 */
* Stub hash: 51f0769423c046d612adf81091192165ad265456 */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_language, 0, 0, MAY_BE_STRING|MAY_BE_BOOL)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, language, IS_STRING, 1, "null")
Expand Down Expand Up @@ -205,7 +205,7 @@ ZEND_END_ARG_INFO()
#endif

#if defined(HAVE_MBREGEX)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_ereg, 0, 2, MAY_BE_LONG|MAY_BE_FALSE)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_ereg, 0, 2, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0)
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(1, matches, "null")
Expand Down
10 changes: 2 additions & 8 deletions ext/mbstring/php_mbregex.c
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ static void _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase)
size_t arg_pattern_len, string_len;
php_mb_regex_t *re;
OnigRegion *regs = NULL;
int i, match_len, beg, end;
int i, beg, end;
OnigOptionType options;
char *str;

Expand Down Expand Up @@ -938,11 +938,8 @@ static void _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase)
goto out;
}

match_len = 1;
str = string;
if (array != NULL) {

match_len = regs->end[0] - regs->beg[0];
for (i = 0; i < regs->num_regs; i++) {
beg = regs->beg[i];
end = regs->end[i];
Expand All @@ -959,10 +956,7 @@ static void _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase)
}
}

if (match_len == 0) {
match_len = 1;
}
RETVAL_LONG(match_len);
RETVAL_TRUE;
out:
if (regs != NULL) {
onig_region_free(regs, 1);
Expand Down
2 changes: 1 addition & 1 deletion ext/mbstring/tests/bug78633.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if (!function_exists('mb_eregi')) die('skip mb_eregi function not available');
--FILE--
<?php
$res = mb_eregi(".+Isssǰ", ".+Isssǰ");
if ($res === 1 || $res === false) {
if (is_bool($res)) {
echo "ok\n";
} else {
var_dump($res);
Expand Down
2 changes: 1 addition & 1 deletion ext/mbstring/tests/mb_ereg-compat-02.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function_exists('mb_ereg') or die("skip mb_ereg() is not available in this build
echo "\n";
?>
--EXPECT--
32
1
This is a nice and simple string
is
is
24 changes: 12 additions & 12 deletions ext/mbstring/tests/mb_ereg.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ output_handler=
}
?>
--EXPECT--
(15)6162632064656620676869206a6b6c2064656620676869206a6b6c
(27)a3e1a3e2a3e320a4a2a4aaa4a420a4aba4b3a4ca20a4efa4f1a4f320a3e1a3e2a3e320a4a2a4aaa4a420a4ab20a4b3a4ca20a4efa4f1a4f3
(27)a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab20a4ada4ab20a4f2a4f020a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab2020a4ada4ab20a4f2a4f0
(15)6162632064656620676869206a6b6c2064656620676869206a6b6c
(27)a3e1a3e2a3e320a4a2a4aaa4a420a4aba4b3a4ca20a4efa4f1a4f320a3e1a3e2a3e320a4a2a4aaa4a420a4ab20a4b3a4ca20a4efa4f1a4f3
(27)a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab20a4ada4ab20a4f2a4f020a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab2020a4ada4ab20a4f2a4f0
(15)6162632064656620676869206a6b6c2064656620676869206a6b6c
(27)a3e1a3e2a3e320a4a2a4aaa4a420a4aba4b3a4ca20a4efa4f1a4f320a3e1a3e2a3e320a4a2a4aaa4a420a4ab20a4b3a4ca20a4efa4f1a4f3
(27)a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab20a4ada4ab20a4f2a4f020a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab2020a4ada4ab20a4f2a4f0
(15)6162632064656620676869206a6b6c2064656620676869206a6b6c
(39)a3e1a3e2a3e320a4a2a4aaa4a420a4aba4b3a4ca20a4efa4f1a4f320a3e1a3e2a3e320a4a2a4aaa4a420a4ab20a4b3a4ca20a4efa4f1a4f3
(39)a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab20a4ada4ab20a4f2a4f020a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab2020a4ada4ab20a4f2a4f0
(1)6162632064656620676869206a6b6c2064656620676869206a6b6c
(1)a3e1a3e2a3e320a4a2a4aaa4a420a4aba4b3a4ca20a4efa4f1a4f320a3e1a3e2a3e320a4a2a4aaa4a420a4ab20a4b3a4ca20a4efa4f1a4f3
(1)a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab20a4ada4ab20a4f2a4f020a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab2020a4ada4ab20a4f2a4f0
(1)6162632064656620676869206a6b6c2064656620676869206a6b6c
(1)a3e1a3e2a3e320a4a2a4aaa4a420a4aba4b3a4ca20a4efa4f1a4f320a3e1a3e2a3e320a4a2a4aaa4a420a4ab20a4b3a4ca20a4efa4f1a4f3
(1)a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab20a4ada4ab20a4f2a4f020a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab2020a4ada4ab20a4f2a4f0
(1)6162632064656620676869206a6b6c2064656620676869206a6b6c
(1)a3e1a3e2a3e320a4a2a4aaa4a420a4aba4b3a4ca20a4efa4f1a4f320a3e1a3e2a3e320a4a2a4aaa4a420a4ab20a4b3a4ca20a4efa4f1a4f3
(1)a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab20a4ada4ab20a4f2a4f020a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab2020a4ada4ab20a4f2a4f0
(1)6162632064656620676869206a6b6c2064656620676869206a6b6c
(1)a3e1a3e2a3e320a4a2a4aaa4a420a4aba4b3a4ca20a4efa4f1a4f320a3e1a3e2a3e320a4a2a4aaa4a420a4ab20a4b3a4ca20a4efa4f1a4f3
(1)a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab20a4ada4ab20a4f2a4f020a3eda3faa3f8a3e6a3f020a4a6a4aaa4ab2020a4ada4ab20a4f2a4f0
12 changes: 6 additions & 6 deletions ext/mbstring/tests/mb_ereg_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,28 @@ Regex encoding set to utf-8

**-- ASCII String --**
-- Without $regs argument--
int(1)
int(1)
bool(true)
bool(true)
--With $regs argument --
int(36)
bool(true)
array(2) {
[0]=>
string(48) "VGhpcyBpcyBhbiBFbmdsaXNoIHN0cmluZy4gMDEyMzQ1Njc4"
[1]=>
string(24) "VGhpcyBpcyBhbiBFbmdsaXM="
}
int(17)
bool(true)
array(1) {
[0]=>
string(24) "VGhpcyBpcyBhbiBFbmdsaXM="
}

**-- Multibyte String --**
-- Without $regs argument --
int(1)
bool(true)
bool(false)
-- With $regs argument --
int(35)
bool(true)
array(3) {
[0]=>
string(48) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzQ="
Expand Down
24 changes: 12 additions & 12 deletions ext/mbstring/tests/mb_ereg_variation3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -69,84 +69,84 @@ echo "Done";
*** Testing mb_ereg() : variation ***

-- Iteration 1 --
int(3)
bool(true)
array(1) {
[0]=>
string(4) "YUIx"
}

-- Iteration 2 --
int(4)
bool(true)
array(1) {
[0]=>
string(8) "YUJjRA=="
}

-- Iteration 3 --
int(4)
bool(true)
array(1) {
[0]=>
string(8) "YWIvPQ=="
}

-- Iteration 4 --
int(2)
bool(true)
array(1) {
[0]=>
string(4) "IAk="
}

-- Iteration 5 --
int(3)
bool(true)
array(1) {
[0]=>
string(4) "MjM0"
}

-- Iteration 6 --
int(9)
bool(true)
array(1) {
[0]=>
string(12) "5pel5pys6Kqe"
}

-- Iteration 7 --
int(4)
bool(true)
array(1) {
[0]=>
string(8) "Zmpkcw=="
}

-- Iteration 8 --
int(9)
bool(true)
array(1) {
[0]=>
string(12) "5pel5pys6Kqe"
}

-- Iteration 9 --
int(5)
bool(true)
array(1) {
[0]=>
string(8) "LiEiKkA="
}

-- Iteration 10 --
int(1)
bool(true)
array(1) {
[0]=>
string(4) "CQ=="
}

-- Iteration 11 --
int(5)
bool(true)
array(1) {
[0]=>
string(8) "SURTSlY="
}

-- Iteration 12 --
int(4)
bool(true)
array(1) {
[0]=>
string(8) "M2I1RA=="
Expand Down
16 changes: 8 additions & 8 deletions ext/mbstring/tests/mb_ereg_variation4.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,21 @@ echo "Done";
*** Testing mb_ereg() : usage variations ***

-- Iteration 1 --
int(47)
bool(true)
array(1) {
[0]=>
string(64) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZMDEyMzTvvJXvvJbvvJfvvJjvvJk="
}

-- Iteration 2 --
int(27)
bool(true)
array(1) {
[0]=>
string(36) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ"
}

-- Iteration 3 --
int(5)
bool(true)
array(1) {
[0]=>
string(8) "MDEyMzQ="
Expand All @@ -99,14 +99,14 @@ bool(false)
bool(false)

-- Iteration 6 --
int(20)
bool(true)
array(1) {
[0]=>
string(28) "MDEyMzTvvJXvvJbvvJfvvJjvvJk="
}

-- Iteration 7 --
int(50)
bool(true)
array(1) {
[0]=>
string(68) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
Expand All @@ -116,14 +116,14 @@ array(1) {
bool(false)

-- Iteration 9 --
int(50)
bool(true)
array(1) {
[0]=>
string(68) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
}

-- Iteration 10 --
int(3)
bool(true)
array(1) {
[0]=>
string(4) "44CC"
Expand All @@ -136,7 +136,7 @@ bool(false)
bool(false)

-- Iteration 13 --
int(5)
bool(true)
array(1) {
[0]=>
string(8) "MDEyMzQ="
Expand Down
8 changes: 4 additions & 4 deletions ext/mbstring/tests/mb_ereg_variation5.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ function base64_encode_var_dump($regs) {
--EXPECT--
*** Testing mb_ereg() : usage variations ***

ASCII String without $regs arg: int(1)
ASCII String without $regs arg: bool(true)
ASCII String with $regs arg:
int(38)
bool(true)
array(1) {
[0]=>
string(52) "VGhpcyBpcyBhbiBFbmdsaXNoIHN0cmluZy4gMDEyMzQ1Njc4OS4="
}

Multibyte String without $regs arg: int(1)
Multibyte String without $regs arg: bool(true)
Multubyte String with $regs arg:
int(53)
bool(true)
array(1) {
[0]=>
string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
Expand Down
Loading