Bug #72691 [Csd]: mb_ereg_search raises a warning if a match zero-width
| From: | cmb@php.net | Date: | Thu, 28 Jul 2016 11:35:25 +0000 |
| Subject: | Bug #72691 [Csd]: mb_ereg_search raises a warning if a match zero-width | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-202666@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72691&edit=1
ID: 72691
Updated by: cmb@php.net
Reported by: ju1ius at laposte dot net
Summary: mb_ereg_search raises a warning if a match
zero-width
Status: Closed
Type: Bug
Package: mbstring related
Operating System: Debian Sid
PHP Version: 5.6.24
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Note that after this fix the actual output still doesn't match the
expected output, due to bug #72693 and probably another (yet
unreported?) issue ("o" instead of "foo").
Previous Comments:
------------------------------------------------------------------------
[2016-07-28 11:34:52] cmb@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=php-src.git;a=commit;h=d276e6a8386a68d57d5dd07c3d7e15de4b03c6b3
Log: Fix #72691: mb_ereg_search raises a warning if a match zero-width
------------------------------------------------------------------------
[2016-07-28 10:04:13] cmb@php.net
Indeed, that warning makes no sense; cf. the behavior of PCRE (see
<https://3v4l.org/bHAla>). It has been mistankenly been
introduced
with the commit <https://github.com/php/php-src/commit/55b5913>.
------------------------------------------------------------------------
[2016-07-28 05:00:12] ju1ius at laposte dot net
Description:
------------
when provided a pattern that produces a zero-width match (empty string),
mb_ereg_search raises:
Warning: mb_ereg_search(): Empty regular expression.
First the warning is misleading, since it should not warn about an 'empty regular
expression', but about a 'zero-width match'.
More importantly this behavior is incorrect. A zero-width result is a perfectly valid match, and
should never raise a warning.
For example, matching the pattern '\A' at position zero should succeed without a warning,
and the resulting position should be zero.
Matching pattern '\s*' against the subject 'foo' at position 1 should succeed
without a warning and the resulting position should be 1.
Test script:
---------------
<?php
$str = 'foo';
mb_ereg_search_init($str);
mb_ereg_search('\A');
var_dump(mb_ereg_search_getpos());
var_dump(mb_ereg_search_getregs());
mb_ereg_search('\s*');
var_dump(mb_ereg_search_getpos());
var_dump(mb_ereg_search_getregs());
mb_ereg_search('\w+');
var_dump(mb_ereg_search_getpos());
var_dump(mb_ereg_search_getregs());
mb_ereg_search('\Z');
var_dump(mb_ereg_search_getpos());
var_dump(mb_ereg_search_getregs());
Expected result:
----------------
int(0)
array(1) {
[0]=>
string(0) ""
}
int(0)
array(1) {
[0]=>
string(0) ""
}
int(3)
array(1) {
[0]=>
string(0) "foo"
}
int(3)
array(1) {
[0]=>
string(0) ""
}
Actual result:
--------------
Warning: mb_ereg_search(): Empty regular expression in ...
int(1)
array(1) {
[0]=>
string(0) ""
}
Warning: mb_ereg_search(): Empty regular expression in ...
int(2)
array(1) {
[0]=>
string(0) ""
}
int(3)
array(1) {
[0]=>
string(1) "o"
}
Warning: mb_ereg_search(): Empty regular expression in ...
int(4)
array(1) {
[0]=>
string(0) ""
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72691&edit=1