Browse Source

Bug 26: Cannot work with filenames starting or ending with space with FTP protocol

https://winscp.net/tracker/26

Source commit: 5447437ca07aff1687dc800bb6cd31d78609d087
Martin Prikryl 10 years ago
parent
commit
c972204140

+ 4 - 4
source/filezilla/FtpListResult.cpp

@@ -1426,14 +1426,14 @@ BOOL CFtpListResult::parseAsMlsd(const char *line, const int linelen, t_director
   else if (!gid.IsEmpty())
     direntry.ownergroup += L" " + gid;
 
-  if (!(str = GetNextToken(line, linelen, tokenlen, pos, 1)))
+  if (line[pos] != L' ')
   {
     return FALSE;
   }
-
+  pos++;
   CString fileName;
-  copyStr(fileName, 0, str, tokenlen, true);
-  CServerPath path(fileName);
+  copyStr(fileName, 0, line + pos, linelen - pos, true);
+  CServerPath path(fileName, false); // do not trim
   direntry.name = path.GetLastSegment();
   if (direntry.name.IsEmpty())
   {

+ 13 - 7
source/filezilla/ServerPath.cpp

@@ -21,11 +21,14 @@ CServerPath::CServerPath(int nServerType)
   m_bEmpty = TRUE;
 }
 
-CServerPath::CServerPath(CString path)
+CServerPath::CServerPath(CString path, bool trim)
 {
   m_nServerType = FZ_SERVERTYPE_FTP;
-  path.TrimLeft( L" " );
-  path.TrimRight( L" " );
+  if (trim)
+  {
+    path.TrimLeft( L" " );
+    path.TrimRight( L" " );
+  }
   if (path == L"")
   {
     m_bEmpty = TRUE;
@@ -44,14 +47,17 @@ CServerPath::CServerPath(CString path)
   else if (path.GetLength() > 2 && path[0] == L'\'' && path.Right(1) == L"'" && path.Find(L'/') == -1 && path.Find(L'\\') == -1)
     m_nServerType |= FZ_SERVERTYPE_SUB_FTP_MVS;
 
-  *this = CServerPath(path, m_nServerType);
+  *this = CServerPath(path, m_nServerType, trim);
 }
 
-CServerPath::CServerPath(CString path, int nServerType)
+CServerPath::CServerPath(CString path, int nServerType, bool trim)
 {
   m_nServerType = nServerType;
-  path.TrimLeft( L" " );
-  path.TrimRight( L" " );
+  if (trim)
+  {
+    path.TrimLeft( L" " );
+    path.TrimRight( L" " );
+  }
   if (path == L"")
   {
     m_bEmpty = TRUE;

+ 2 - 2
source/filezilla/ServerPath.h

@@ -13,8 +13,8 @@ public:
   CString GetLastSegment() const;
   CServerPath();
   CServerPath(int nServerType);
-  CServerPath(CString path);
-  CServerPath(CString path, int nServerType);
+  CServerPath(CString path, bool trim = true);
+  CServerPath(CString path, int nServerType, bool trim = true);
   CServerPath(CString subdir, const CServerPath & parent); // If subdir is absolute, parent is ignored
   CServerPath(const CServerPath & path);