Bug #53118 [Opn->Bgs]: preg_split with a subpattern fails on some specific input
Edit report at http://bugs.php.net/bug.php?id=53118&edit=1
ID: 53118
Updated by: felipe@php.net
Reported by: phpuser at thankyou2010 dot com
Summary: preg_split with a subpattern fails on some specific
input
-Status: Open
+Status: Bogus
Type: Bug
Package: PCRE related
Operating System: Win/lin
PHP Version: 5.3.3
Block user comment: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2010-10-20 20:44:04] 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] =>
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53118&edit=1
Thread (2 messages)