]> granicus.if.org Git - curl/commitdiff
FTP: remove trailing slash from path for LIST/MLSD
authorZenju <zenju@gmx.de>
Fri, 13 Sep 2019 15:32:04 +0000 (17:32 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 18 Sep 2019 07:27:21 +0000 (09:27 +0200)
Closes #4348

lib/ftp.c
tests/data/test1010
tests/data/test1149
tests/data/test244
tests/data/test539

index 00233a80d781fa3d7be0a161c88dd1376113f013..068a1a024b160b4f8219492e8ddb060d2fd074b6 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -1446,20 +1446,19 @@ static CURLcode ftp_state_list(struct connectdata *conn)
      The other ftp_filemethods will CWD into dir/dir/ first and
      then just do LIST (in that case: nothing to do here)
   */
-  char *cmd, *lstArg, *slashPos;
+  char *cmd, *lstArg;
   const char *inpath = ftp->path;
 
   lstArg = NULL;
   if((data->set.ftp_filemethod == FTPFILE_NOCWD) &&
      inpath && inpath[0] && strchr(inpath, '/')) {
-    size_t n = strlen(inpath);
+    /* chop off the file part if format is dir/file
+       otherwise remove the trailing slash for dir/dir/
+       and full paths like %2f/ except for /        */
+    size_t n = strrchr(inpath, '/') - inpath;
+    if(n == 0)
+      ++n;
 
-    /* Check if path does not end with /, as then we cut off the file part */
-    if(inpath[n - 1] != '/') {
-      /* chop off the file part if format is dir/dir/file */
-      slashPos = strrchr(inpath, '/');
-      n = slashPos - inpath;
-    }
     result = Curl_urldecode(data, inpath, n, &lstArg, NULL, TRUE);
     if(result)
       return result;
index b2083af7b625c319d8a037e1cd364a7926bd7050..ef073f5e5a008568f983c3920e001776120329af 100644 (file)
@@ -49,9 +49,9 @@ PASS ftp@example.com
 PWD\r
 EPSV\r
 TYPE A\r
-LIST /list/this/path/1010/\r
+LIST /list/this/path/1010\r
 EPSV\r
-LIST /list/this/path/1010/\r
+LIST /list/this/path/1010\r
 QUIT\r
 </protocol>
 </verify>
index f826391e9df551544c32aa4006eb6f746daba14a..f0c297dc117b782033a05ca5146c07da6f5c5fa8 100644 (file)
@@ -57,7 +57,7 @@ TYPE A
 LIST\r
 CWD /\r
 EPSV\r
-LIST list/this/path/1149/\r
+LIST list/this/path/1149\r
 QUIT\r
 </protocol>
 </verify>
index 8ce4b634654f80aa5b6e86f79d3b6721b4ce39e0..080163dd17b14f6c2f207c1ca1781317811fc376 100644 (file)
@@ -47,7 +47,7 @@ PASS ftp@example.com
 PWD\r
 EPSV\r
 TYPE A\r
-LIST fir#t/third/244/\r
+LIST fir#t/third/244\r
 QUIT\r
 </protocol>
 </verify>
index e9aadd1f316073b754c91cf7ddfa667f1974ebca..a69834012a0831a853f7b5dbd268890181b18bad 100644 (file)
@@ -64,7 +64,7 @@ SYST
 CWD /\r
 EPSV\r
 TYPE A\r
-LIST path/to/the/file/539./\r
+LIST path/to/the/file/539.\r
 QUIT\r
 </protocol>
 </verify>