# [PATCH] Bug# 27633 - Wrong translation in ASCII mode

- Thread: https://externals.io/message/14530
- Original archive: https://news-web.php.net/php.internals/14530
- Started by Binam on 2005-02-02T20:11:30+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #14530 — Binam — 2005-02-02T20:11:30+00:00

URL: https://externals.io/message/14530#14530

WTF?? Appearently the attachment is getting stripped off somewhere along
the way...
 
Index: ext/ftp/ftp.c
===================================================================
RCS file: /repository/php-src/ext/ftp/ftp.c,v
retrieving revision 1.106
diff -u -r1.106 ftp.c
--- ext/ftp/ftp.c 5 Oct 2004 23:53:09 -0000 1.106
+++ ext/ftp/ftp.c 2 Feb 2005 19:09:28 -0000
@@ -846,16 +846,25 @@
     * Everything Else \n
     */
 #ifdef PHP_WIN32
-   while ((s = strpbrk(ptr, "\r\n"))) {
-    if (*s == '\n') {
-     php_stream_putc(outstream, '\r');
+   while ((s = strpbrk(ptr, "\r\n")) && (s < e)) {
+
+    /* 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.
+     */
+
+    php_stream_write(outstream, ptr, (s - ptr));
+    php_stream_putc(outstream, '\r');
+    php_stream_putc(outstream, '\n');
+    if (*s == '\r' && *(s + 1) == '\r' && *(s + 2) == '\n') {
+     s += 3;
     } else if (*s == '\r' && *(s + 1) == '\n') {
+     s += 2;
+    } else if (*s == '\r') { 
+     s++;
+    } else if (*s == '\n') {
      s++;
-    }
-    s++;
-    php_stream_write(outstream, ptr, (s - ptr));
-    if (*(s - 1) == '\r') {
-     php_stream_putc(outstream, '\n');
     }
     ptr = s;
    }
