php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72691 mb_ereg_search raises a warning if a match zero-width
Submitted: 2016-07-28 05:00 UTC Modified: 2016-07-28 12:02 UTC
From: ju1ius at laposte dot net Assigned: cmb (profile)
Status: Closed Package: mbstring related
PHP Version: 5.6.24 OS: Debian Sid
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ju1ius at laposte dot net
New email:
PHP Version: OS:

 

 [2016-07-28 05:00 UTC] 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) ""
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-28 10:04 UTC] cmb@php.net
-Status: Open +Status: Analyzed -Assigned To: +Assigned To: cmb
 [2016-07-28 10:04 UTC] 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 11:34 UTC] 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 11:34 UTC] cmb@php.net
-Status: Analyzed +Status: Closed
 [2016-07-28 11:35 UTC] cmb@php.net
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").
 [2016-07-28 12:02 UTC] cmb@php.net
> due to bug #72693 and probably another (yet unreported?) issue
> ("o" instead of "foo").

No, this issue is also caused by #72693.
 [2016-10-17 10:10 UTC] bwoebi@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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 22:01:28 2024 UTC