浏览代码

Bug 2004: Restore compatibility with FTP servers the return malformed cdir and pdir entries in directory listing

https://winscp.net/tracker/2004
(cherry picked from commit a80981d228d31f1ec9234fb481441e0b5d82a479)

Source commit: d339192caf23daba9fa26b97b92431c6efa7e240
Martin Prikryl 4 年之前
父节点
当前提交
3a383d55fe
共有 1 个文件被更改,包括 23 次插入14 次删除
  1. 23 14
      source/filezilla/FtpListResult.cpp

+ 23 - 14
source/filezilla/FtpListResult.cpp

@@ -965,6 +965,7 @@ BOOL CFtpListResult::parseAsMlsd(const char *line, const int linelen, t_director
   {
     return FALSE;
   }
+  direntry.name = L"";
   direntry.bUnsure = FALSE;
   direntry.dir = FALSE;
   direntry.bLink = FALSE;
@@ -1029,15 +1030,20 @@ BOOL CFtpListResult::parseAsMlsd(const char *line, const int linelen, t_director
         if ((value.GetLength() > 14) && (value[13] == ':'))
           direntry.linkTarget = value.Mid(14);
       }
-      // ProFTPD up to 1.3.6rc1 and 1.3.5a incorrectly uses "cdir" for the current working directory.
-      // So at least in MLST, where this would be the only entry, we treat it like "dir".
       // For MLSD, these will be skipped in AddData.
       else if (!value.CompareNoCase(L"cdir"))
       {
+        // ProFTPD up to 1.3.6rc1 and 1.3.5a incorrectly uses "cdir" for the current working directory.
+        // So at least in MLST, where this would be the only entry, we treat it like "dir".
+        if (!m_mlst)
+        {
+          direntry.name = L".";
+        }
         direntry.dir = TRUE;
       }
       else if (!value.CompareNoCase(L"pdir"))
       {
+        direntry.name = L"..";
         direntry.dir = TRUE;
       }
     }
@@ -1120,23 +1126,26 @@ BOOL CFtpListResult::parseAsMlsd(const char *line, const int linelen, t_director
   {
     return FALSE;
   }
-  pos++;
-  CString fileName;
-  copyStr(fileName, 0, line + pos, linelen - pos, true);
-  if (m_mlst)
+  if (direntry.name.IsEmpty())
   {
-    // do not try to detect path type, assume a standard *nix syntax + do not trim
-    CServerPath path(fileName, FZ_SERVERTYPE_FTP, false);
-    direntry.name = path.GetLastSegment();
-    if (direntry.name.IsEmpty())
+    pos++;
+    CString fileName;
+    copyStr(fileName, 0, line + pos, linelen - pos, true);
+    if (m_mlst)
+    {
+      // do not try to detect path type, assume a standard *nix syntax + do not trim
+      CServerPath path(fileName, FZ_SERVERTYPE_FTP, false);
+      direntry.name = path.GetLastSegment();
+      if (direntry.name.IsEmpty())
+      {
+        direntry.name = fileName;
+      }
+    }
+    else
     {
       direntry.name = fileName;
     }
   }
-  else
-  {
-    direntry.name = fileName;
-  }
   return TRUE;
 }