php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53118 preg_split with a subpattern fails on some specific input
Submitted: 2010-10-20 20:44 UTC Modified: 2010-11-10 23:34 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: phpuser at thankyou2010 dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.3.3 OS: Win/lin
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: phpuser at thankyou2010 dot com
New email:
PHP Version: OS:

 

 [2010-10-20 20:44 UTC] phpuser at thankyou2010 dot com
Description:
------------
preg_split fails on some specific input, which seems to be caused by a subpattern. If in the testcode I reduce the length of the string in between the middle [..], it works fine.

Test script:
---------------
<?php
$input = '[a][012345678901234 ][a]';

// first match a [, then anything but spaces, end with ]
$tokens = preg_split('/\\[([^\\s]*)*\\]/U', $input);
print_r($tokens);


$tokens = preg_split('/\\[[^\\s]*\\]/U', $input);
print_r($tokens);

Expected result:
----------------
Array
(
    [0] =>
    [1] => [012345678901234 ]
    [2] =>
)
Array
(
    [0] =>
    [1] => [012345678901234 ]
    [2] =>
)

Actual result:
--------------
Array
(
    [0] =>
    [1] => [012345678901234 ][a]
)
Array
(
    [0] =>
    [1] => [012345678901234 ]
    [2] =>
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-10 23:34 UTC] felipe@php.net
-Status: Open +Status: Bogus
 [2010-11-10 23:34 UTC] felipe@php.net
This is because the default backtrack_limit size. Set it to a big value so it will work.

e.g.
ini_set('pcre.backtrack_limit', PHP_INT_MAX);
$input = '[a][012345678901234 ][a]';
$tokens = preg_split('/\\[([^\\s]*)*\\]/U', $input);
print_r($tokens);

You can check the preg_last_error() return to detect such errors.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed May 25 10:03:33 2022 UTC