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

From: Date: Sat, 11 Oct 2003 13:06:27 +0000
Subject: #87 [NEW]: readLine() method has problems with "\n" line endings
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-22595@lists.php.net to get a copy of this message
From: avb@php.net Operating system: Any PHP version: Irrelevant PHP Bug Type: Net_Socket Bug description: readLine() method has problems with "\n" line endings 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 bug report at http://pear.php.net/bugs/bug.php?id=87&edit=1 --

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