php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72694 mb_ereg_search_setpos does not accept a string's last position
Submitted: 2016-07-28 06:01 UTC Modified: 2016-07-28 14:01 UTC
From: ju1ius at laposte dot net Assigned: cmb (profile)
Status: Closed Package: mbstring related
PHP Version: 5.6.24 OS:
Private report: No CVE-ID: None
 [2016-07-28 06:01 UTC] ju1ius at laposte dot net
Description:
------------
When calling `mb_ereg_search_setpos` with the end position of a string as argument, it raises a warning and returns false and resets the search position to zero.

This prevents `mb_ereg_search` to match at the end of the string (for example zero-width assertions like '\Z', '$' or lookbehinds).

The correct behavior should be to not throw a warning, and set the position accordingly.

What's more, once you call `mb_ereg_search_setpos(strlen($str))`, the `mb_ereg_search` behavior seems to be erratic, see the test script, where the '\Z' assertion matches and sets position to 3 eventhough `mb_ereg_search_getpos` just returned 0 !

Test script:
---------------
mb_ereg_search_init('foo');

var_dump(mb_ereg_search_setpos(3));
var_dump(mb_ereg_search_getpos());

var_dump(mb_ereg_search('\Z'));
var_dump(mb_ereg_search_getpos());

Expected result:
----------------
bool(true)
int(3)

bool(true)
int(3)

Actual result:
--------------
Warning: mb_ereg_search_setpos(): Position is out of range in ...
bool(false)
int(0)

Warning: mb_ereg_search(): Empty regular expression in ...
bool(true)
int(3)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-28 13:04 UTC] cmb@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2016-07-28 13:04 UTC] cmb@php.net
Confirmed: <https://3v4l.org/YqVeH>.
 [2016-07-28 13:58 UTC] cmb@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=php-src.git;a=commit;h=ee6900c3de68f1b94dfae8e230c7fa755c7fa595
Log: Fix #72694: mb_ereg_search_setpos does not accept a string's last position
 [2016-07-28 13:58 UTC] cmb@php.net
-Status: Verified +Status: Closed
 [2016-07-28 14:01 UTC] cmb@php.net
Thank you for the reports, and for helping us make PHP better.
 [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=ee6900c3de68f1b94dfae8e230c7fa755c7fa595
Log: Fix #72694: mb_ereg_search_setpos does not accept a string's last position
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC