Bug #72691 [Opn->Ana]: mb_ereg_search raises a warning if a match zero-width
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: Open
+Status: Analyzed
Type: Bug
Package: mbstring related
Operating System: Debian Sid
PHP Version: 5.6.24
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
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>.
Previous Comments:
------------------------------------------------------------------------
[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
Thread (5 messages)