From:             m_v_ at gmx dot net
Operating system: Windows Vista Home Premium
PHP version:      5CVS-2007-05-25 (snap)
PHP Bug Type:     PCRE related
Bug description:  Preg_Split returns 3 matches with offset -1

Description:
------------
preg_split behaves unexpectet with certain pattern (see reproduce code):

It returns tripple offsets with the offsetvalue -1.

It gets even worse when you replace:

 $reg = "~\{(literal)\}(.*?)\{(/literal)\}|\{(.*?)\}~s";
with
 $reg = "~\{\*(literal)\}(.*?)\{(/literal)\}|\{(.*?)\}~s";

it simply returns several off those empty string, offset -1 triples.


P.S.: Hope it is actually a bug and not my ignorance of regex, however i
asked in a forum if anybody knew where the mistake is and i got no answer
and in addition the offset -1 mykes it look like a bug to me.
If it however should be a mistake in my regex it would be kind if you
would let me know how to put it.

Thx in advance

Reproduce code:
---------------
$reg = "~\{(literal)\}(.*?)\{(/literal)\}|\{(.*?)\}~s";
echo $reg.'<br>';
$res = preg_split( $reg, "df{g}s{literal}asd{as}d{/literal}", -1,
PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_OFFSET_CAPTURE );
echo '<pre>'.print_r($res, 1).'</pre>';

Expected result:
----------------
~\{(literal)\}(.*?)\{(/literal)\}|\{(.*?)\}~s

Array
(
    [0] => Array
        (
            [0] => df
            [1] => 0
        )

    [1] => Array
        (
            [0] => g
            [1] => 3
        )

    [2] => Array
        (
            [0] => s
            [1] => 5
        )

    [3] => Array
        (
            [0] => literal
            [1] => 7
        )

    [4] => Array
        (
            [0] => asd{as}d
            [1] => 15
        )

    [5] => Array
        (
            [0] => /literal
            [1] => 24
        )

    [6] => Array
        (
            [0] => 
            [1] => 33
        )

)


Actual result:
--------------
~\{(literal)\}(.*?)\{(/literal)\}|\{(.*?)\}~s

Array
(
    [0] => Array
        (
            [0] => df
            [1] => 0
        )

    [1] => Array
        (
            [0] => 
            [1] => -1
        )

    [2] => Array
        (
            [0] => 
            [1] => -1
        )

    [3] => Array
        (
            [0] => 
            [1] => -1
        )

    [4] => Array
        (
            [0] => g
            [1] => 3
        )

    [5] => Array
        (
            [0] => s
            [1] => 5
        )

    [6] => Array
        (
            [0] => literal
            [1] => 7
        )

    [7] => Array
        (
            [0] => asd{as}d
            [1] => 15
        )

    [8] => Array
        (
            [0] => /literal
            [1] => 24
        )

    [9] => Array
        (
            [0] => 
            [1] => 33
        )

)


-- 
Edit bug report at http://bugs.php.net/?id=41496&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=41496&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=41496&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=41496&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=41496&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=41496&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=41496&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=41496&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=41496&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=41496&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=41496&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=41496&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=41496&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=41496&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=41496&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=41496&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=41496&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=41496&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=41496&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=41496&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=41496&r=mysqlcfg

Reply via email to