]> granicus.if.org Git - php/commitdiff
MFH: Fixed bug #27633 (Double \r problem on ftp_get in ASCII mode on Win32).
authorIlia Alshanetsky <iliaa@php.net>
Thu, 17 Feb 2005 15:38:34 +0000 (15:38 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Thu, 17 Feb 2005 15:38:34 +0000 (15:38 +0000)
NEWS
ext/ftp/ftp.c

diff --git a/NEWS b/NEWS
index 2cc049153b1caed523349cd01bf280f13e8395f0..eb268f0833b2c342f373e3985ed87d77c7c64dd7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -77,6 +77,7 @@ PHP 4                                                                      NEWS
 - Fixed bug #28086 (crash inside overload() function). (Tony) 
 - Fixed bug #28074 (FastCGI: stderr should be written in a FCGI stderr stream).
   (chris at ex-parrot dot com)
+- Fixed bug #27633 (Double \r problem on ftp_get in ASCII mode on Win32). (Ilia)
 - Fixed bug #7782 (Cannot use PATH_INFO fully with php isapi). (Unknown)
 
 15 Dec 2004, Version 4.3.10
index d6bf5a95de0a9eb9caf0db3851a4d18c9ce070e2..c44662f629ef9e7077d162c0a367572c5f075fda 100644 (file)
@@ -713,16 +713,22 @@ ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type,
                         * Everything Else \n
                         */
 #ifdef PHP_WIN32
-                       while ((s = strpbrk(ptr, "\r\n"))) {
-                               if (*s == '\n') {
-                                       php_stream_putc(outstream, '\r');
-                               } else if (*s == '\r' && *(s + 1) == '\n') {
-                                       s++;
-                               }
-                               s++;
+                       while ((s = strpbrk(ptr, "\r\n")) && (s < e)) {
                                php_stream_write(outstream, ptr, (s - ptr));
-                               if (*(s - 1) == '\r') {
-                                       php_stream_putc(outstream, '\n');
+                               php_stream_write(outstream, "\r\n", sizeof("\r\n")-1);
+
+                               if (*s == '\r') {
+                                       *s++;
+                               }
+                               /* for some reason some servers prefix a \r before a \n, 
+                                * resulting in a \r\r\n in the buffer when
+                                * the remote file already has windoze style line endings.
+                                */
+                               if (*s == '\r') {
+                                       *s++;
+                               }
+                               if (*s == '\n') {
+                                       *s++;
                                }
                                ptr = s;
                        }