php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80866 preg_split ignores limit flag when pattern with \K has 0-width fullstring match
Submitted: 2021-03-15 02:02 UTC Modified: -
From: mickmackusa at mickmack dot usa Assigned:
Status: Closed Package: PCRE related
PHP Version: 7.3.27 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mickmackusa at mickmack dot usa
New email:
PHP Version: OS:

 

 [2021-03-15 02:02 UTC] mickmackusa at mickmack dot usa
Description:
------------
preg_split() does not respect the limit parameter when \K is used to produce a zero-width fullstring delimiter. https://3v4l.org/kQHQZ This bug seems to be present since PHP7.3.  Other preg_split() calls using zero-width-match-producing regular expressions do not suffer the same bug. 
https://3v4l.org/3KP1T

Test script:
---------------
var_export(preg_split('~.{3}\K~', 'abcdefghijklm', 3));

Expected result:
----------------
array (
  0 => 'abc',
  1 => 'def',
  2 => 'ghijklm',
)

Actual result:
--------------
array (
  0 => 'abc',
  1 => 'def',
  2 => 'ghi',
  3 => 'jkl',
  4 => 'm',
)

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-03-15 12:23 UTC] dharman@php.net
The following pull request has been associated:

Patch Name: Fix bug 80866
On GitHub:  https://github.com/php/php-src/pull/6774
Patch:      https://github.com/php/php-src/pull/6774.patch
 [2021-03-15 13:48 UTC] nikic@php.net
Automatic comment on behalf of tekiela246@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=282355efd5d53ba180d30794737c33898031104e
Log: Fix bug #80866
 [2021-03-15 13:48 UTC] nikic@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 10:01:29 2024 UTC