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

From: Date: Sat, 18 Oct 2003 14:11:40 +0000
Subject: Re: #87 [Ver]: readLine() method has problems with "\n" line endings
References: 1 2  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-22791@lists.php.net to get a copy of this message
try this code (untested) if (strlen($line) >= 1 && substr($line, -1) == "\n") {
    return rtrim($line, "\r\n");
} Greg Heino H. Gehlsen wrote:
rtrim() eats more than \r and \n - a \t at the end of the line (just before \r or \n) would be trim'ed as well... ----- Original Message ----- From: <neufeind@php.net> To: <pear-dev@lists.php.net>; <ssb@fast.no>; <chuck@horde.org> Sent: Saturday, October 18, 2003 12:57 PM Subject: [PEAR-DEV] [PEAR-BUG] #87 [Ver]: readLine() method has problems with "\n" line endings
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 -- PEAR Development Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


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