Blob Blame History Raw
 CHANGES    |    4 ++++
 src/main.c |   23 ++++++++++++++++++++---
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/CHANGES b/CHANGES
index 7928690..92c2753 100644
--- a/CHANGES
+++ b/CHANGES
@@ -17,6 +17,10 @@ Kamil Dudka (24 Apr 2010)
 - Fixed SSL handshake timeout underflow in libcurl-NSS, which caused test405
   to hang on a slow machine.
 
+Daniel Stenberg (19 Apr 2010)
+- -J/--remote-header-name didn't strip trailing carriage returns or linefeeds
+  properly, so they could be used in the file name.
+
 Version 7.20.1 (14 April 2010)
 
 Daniel Stenberg (9 Apr 2010)
diff --git a/src/main.c b/src/main.c
index 6e3ef3d..d532846 100644
--- a/src/main.c
+++ b/src/main.c
@@ -4200,9 +4200,26 @@ parse_filename(char *ptr, size_t len)
     }
   }
 
-  q = strrchr(p, quote);
-  if (q)
-    *q = 0;
+  if(quote) {
+    /* if the file name started with a quote, then scan for the end quote and
+       stop there */
+    q = strrchr(p, quote);
+    if (q)
+      *q = 0;
+  }
+  else
+    q = NULL; /* no start quote, so no end has been found */
+
+  if(!q) {
+    /* make sure the file name doesn't end in \r or \n */
+    q = strchr(p, '\r');
+    if(q)
+      *q  = 0;
+
+    q = strchr(p, '\n');
+    if(q)
+      *q  = 0;
+  }
 
   if (copy!=p)
     memmove(copy, p, strlen(p)+1);