#43522 [Opn]: stream_get_line eats additional characters
| From: | felipe@php.net | Date: | Sat, 08 Dec 2007 20:25:55 +0000 |
| Subject: | #43522 [Opn]: stream_get_line eats additional characters | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-120480@lists.php.net to get a copy of this message | ||
ID: 43522
Updated by: felipe@php.net
Reported By: tylera at iproduction dot com
Status: Open
Bug Type: Streams related
Operating System: Gentoo Linux, Win32, Solaris
PHP Version: 5.2.5
New Comment:
Simple patch for it:
http://ecl.zoone.com.br/etc/patches/bug43522.patch
Previous Comments:
------------------------------------------------------------------------
[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