From: inf3rno dot hu at gmail dot com
Operating system: Windows XP
PHP version: 5.2.10
PHP Bug Type: PCRE related
Bug description: Incorrect result for .*
Description:
------------
For pattern: .* there is an empty match at the end of the string.
Reproduce code:
---------------
$p1='/.*/';
$p2='/.*$/';
$p3='/^.*/';
$p4='/^.*$/';
$test='some text';
function test($p,$t)
{
preg_match_all($p,$t,$m,PREG_SET_ORDER);
echo $p.'<br />';
if (count($m)==1)
echo '<div style="color: green;">ok</div>';
else
echo '<div style="color: red;">bug</div>';
echo '<pre>'.var_export($m,true).'</pre>';
echo '<br /><br />';
}
test($p1,$test);
test($p2,$test);
test($p3,$test);
test($p4,$test);
Expected result:
----------------
I'm expecting one match in the preg_match_all result array, and I will get
two instead of one. The second match is empty.
Actual result:
--------------
/.*/
bug
array (
0 =>
array (
0 => 'some text',
),
1 =>
array (
0 => '',
),
)
/.*$/
bug
array (
0 =>
array (
0 => 'some text',
),
1 =>
array (
0 => '',
),
)
/^.*/
ok
array (
0 =>
array (
0 => 'some text',
),
)
/^.*$/
ok
array (
0 =>
array (
0 => 'some text',
),
)
--
Edit bug report at http://bugs.php.net/?id=49198&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=49198&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=49198&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=49198&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=49198&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=49198&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=49198&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=49198&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=49198&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=49198&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=49198&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=49198&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=49198&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=49198&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=49198&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49198&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=49198&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=49198&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=49198&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=49198&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=49198&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=49198&r=mysqlcfg