#87 [Ver]: readLine() method has problems with "\n" line endings

From: Date: Sat, 18 Oct 2003 10:57:48 +0000
Subject: #87 [Ver]: readLine() method has problems with "\n" line endings
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-22788@lists.php.net to get a copy of this message
ID: 87 Updated by: neufeind@php.net Reported By: avb@php.net Status: Verified Bug Type: Net_Socket Operating System: Any PHP Version: Irrelevant New Comment: How about this code (lines 396-400) in Net_Socket if (strlen($line) >= 1 && (substr($line, -1) == "\n")) { return rtrim($line); } Should be enough, right? Previous Comments: ------------------------------------------------------------------------ [2003-10-11 09:06:27] avb@php.net Description: ------------ This code (lines 396-400) in Net_Socket if (strlen($line) >= 2 && (substr($line, -2) == "\r\n" || substr($line, -1) == "\n")) { return rtrim($line); } prevent the method from correctly returning an empty string if a line containing just "\n" is read from socket. Reproduce code: --------------- sock-bug.php: <?php require_once 'Net/Socket.php'; $sock =& new Net_Socket(); // To be able to test with local file instead of real socket... $sock->fp = fopen('sock-bug.txt', 'rb'); $i = 1; while (!$sock->eof()) { $line = $sock->readLine(); echo $i++ . ':' . $line . "\n"; } // while ?> sock-bug.txt (should have \n line endings!): foo bar baz Expected result: ---------------- 1:foo 2: 3:bar 4: 5: 6:baz Actual result: -------------- 1:foo 2: bar 3: 4:baz ------------------------------------------------------------------------ -- Edit this bug report at http://pear.php.net/bugs/bug.php?id=87&edit=1

« previous php.pear.dev (#22788) next »