Skip to content

Commit

Permalink
Bug 1993: When installing an extension from a file, it is always save…
Browse files Browse the repository at this point in the history
…d in UTF-8 with BOM, disregarding the original encoding

https://winscp.net/tracker/1993

+ When installing from a URL, not saving the extension with BOM (to allow downloading extensions in languages that do not support it, like batch files)

(cherry picked from commit fb7bad0)

Source commit: 8856e5ac8c6e543eac588bc7bef7d7792a0be2c7
  • Loading branch information
martinprikryl committed Jun 15, 2021
1 parent 2457fee commit 9a59d27
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion source/forms/Preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#pragma hdrstop

#include <StrUtils.hpp>
#include <System.IOUtils.hpp>
#include <Common.h>
#include <math.h>

Expand Down Expand Up @@ -2647,6 +2648,7 @@ void __fastcall TPreferencesDialog::AddExtension()
bool Latest;
UnicodeString FileName;
UnicodeString ExtensionPath;
UnicodeString LinesSourcePath;
std::unique_ptr<TStringList> Lines(new TStringList());
std::unique_ptr<TCustomCommandType> CustomCommand;

Expand Down Expand Up @@ -2716,6 +2718,7 @@ void __fastcall TPreferencesDialog::AddExtension()
ProvisionaryId = WinConfiguration->GetProvisionaryExtensionId(FileName);
}

LinesSourcePath = Path;
LoadScriptFromFile(Path, Lines.get());
}

Expand Down Expand Up @@ -2787,7 +2790,16 @@ void __fastcall TPreferencesDialog::AddExtension()
ExtensionPath = WinConfiguration->UniqueExtensionName(LeftStr(OriginalExtensionPath, P - 1), Counter) + RightStr(OriginalExtensionPath, OriginalExtensionPath.Length() - P + 1);
}

Lines->SaveToFile(ApiPath(ExtensionPath));
if (!LinesSourcePath.IsEmpty())
{
// Copy as is, exactly preserving the file encoding
TFile::Copy(ApiPath(LinesSourcePath), ApiPath(ExtensionPath));
}
else
{
Lines->WriteBOM = false;
Lines->SaveToFile(ApiPath(ExtensionPath));
}

FAddedExtensions->Add(ExtensionPath);
}
Expand Down

0 comments on commit 9a59d27

Please sign in to comment.