Skip to content

Commit

Permalink
Bug 2085: Workaround for specific encoding of commas in filenames (an…
Browse files Browse the repository at this point in the history
…d particularly directory names) by OneDrive WebDAV interface

https://winscp.net/tracker/2085
(cherry picked from commit 33bfa5d)

Source commit: d5d932fa931f2b89f350fd0ef774101d384091ee
  • Loading branch information
martinprikryl committed Jun 8, 2022
1 parent c89337f commit 52aa873
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions source/core/WebDAVFileSystem.cpp
Expand Up @@ -828,14 +828,17 @@ void TWebDAVFileSystem::NeonPropsResult(
TReadFileData & Data = *static_cast<TReadFileData *>(UserData);
if (Data.FileList != NULL)
{
UnicodeString FileListPath = Data.FileSystem->AbsolutePath(Data.FileList->Directory, false);
if (UnixSamePath(Path, FileListPath))
{
Path = UnixIncludeTrailingBackslash(UnixIncludeTrailingBackslash(Path) + PARENTDIRECTORY);
}
std::unique_ptr<TRemoteFile> File(new TRemoteFile(NULL));
File->Terminal = Data.FileSystem->FTerminal;
Data.FileSystem->ParsePropResultSet(File.get(), Path, Results);

UnicodeString FileListPath = Data.FileSystem->AbsolutePath(Data.FileList->Directory, false);
if (UnixSamePath(File->FullFileName, FileListPath))
{
File->FileName = PARENTDIRECTORY;
File->FullFileName = UnixCombinePaths(Path, PARENTDIRECTORY);
}

Data.FileList->AddFile(File.release());
}
else
Expand Down Expand Up @@ -947,7 +950,9 @@ void __fastcall TWebDAVFileSystem::ParsePropResultSet(TRemoteFile * File,
// so if we see one in the display name, take the name from there.
// * and % won't help, as OneDrive seem to have bug with % at the end of the filename,
// and the * (and others) is removed from file names.
if (FOneDrive && (ContainsText(File->FileName, L"^") || (wcspbrk(File->DisplayName.c_str(), L"&,+#[]%*") != NULL)))
// Filenames with commas (,) get as many additional characters at the end of the filename as there are commas.
if (FOneDrive &&
(ContainsText(File->FileName, L"^") || ContainsText(File->FileName, L",") || (wcspbrk(File->DisplayName.c_str(), L"&,+#[]%*") != NULL)))
{
File->FileName = File->DisplayName;
File->FullFileName = UnixCombinePaths(UnixExtractFileDir(File->FullFileName), File->FileName);
Expand Down

0 comments on commit 52aa873

Please sign in to comment.