#43522 [Opn->Csd]: stream_get_line eats additional characters
| From: | iliaa@php.net | Date: | Mon, 10 Dec 2007 14:19:32 +0000 |
| Subject: | #43522 [Opn->Csd]: stream_get_line eats additional characters | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-120529@lists.php.net to get a copy of this message | ||
ID: 43522
Updated by: iliaa@php.net
Reported By: tylera at iproduction dot com
-Status: Open
+Status: Closed
Bug Type: Streams related
Operating System: Gentoo Linux, Win32, Solaris
PHP Version: 5.2.5
New Comment:
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at
http://www.php.net/downloads.php
Previous Comments:
------------------------------------------------------------------------
[2007-12-08 20:25:55] felipe@php.net
Simple patch for it:
http://ecl.zoone.com.br/etc/patches/bug43522.patch
------------------------------------------------------------------------
[2007-12-06 17:16:21] tylera at iproduction dot com
Description:
------------
Calling stream_get_line may eat additional characters when reading a
long line. If the delimiter is not encountered, a number of additional
characters are removed from the stream and are not returned with the
next call to stream_get_line. For some unknown reason, adding \r to the
delimiter makes it work just fine.
Reproduce code:
---------------
<?PHP // 1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ
$fp = fopen('test.php', 'r'); // Open myself
DoTest($fp, 'ZZZ'); // Removes 3 characters
DoTest($fp, "\r"); // Doesn't break with \r for some reason
function DoTest($fp, $delim) {
echo "Delim: " . urlencode($delim) . "\n";
rewind($fp);
echo " " . stream_get_line($fp, 10, $delim) . "\n";
echo " " . stream_get_line($fp, 10, $delim) . "\n";
}
Expected result:
----------------
Delim: ZZZ
<?PHP // 1
234567890A
Delim: %0D
<?PHP // 1
234567890A
Actual result:
--------------
Delim: ZZZ
<?PHP // 1
567890ABCD
Delim: %0D
<?PHP // 1
234567890A
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=43522&edit=1