From d756f991babc5742c6c9c7fcf2dc588c5715d1d3 Mon Sep 17 00:00:00 2001 From: DasSkelett Date: Mon, 12 Apr 2021 02:25:46 +0200 Subject: [PATCH] Tell SharpZipLib to use Unicode when opening zips --- Core/Net/NetFileCache.cs | 7 +++++++ Tests/Core/Cache.cs | 13 ++++++++++++- Tests/Data/TestData.cs | 5 +++++ Tests/Data/ZipWithUnicodeChars.zip | Bin 0 -> 410 bytes Tests/GUI/GH1866.cs | 1 + 5 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 Tests/Data/ZipWithUnicodeChars.zip diff --git a/Core/Net/NetFileCache.cs b/Core/Net/NetFileCache.cs index 3c91a02211..6aec3f94cd 100644 --- a/Core/Net/NetFileCache.cs +++ b/Core/Net/NetFileCache.cs @@ -35,6 +35,13 @@ public class NetFileCache : IDisposable private static readonly Regex cacheFileRegex = new Regex("^[0-9A-F]{8}-", RegexOptions.Compiled); private static readonly ILog log = LogManager.GetLogger(typeof (NetFileCache)); + static NetFileCache() + { + // SharpZibLib 1.1.0 changed this to default to false, but we depend on it for international mods. + // https://github.com/icsharpcode/SharpZipLib/issues/591 + ZipStrings.UseUnicode = true; + } + /// /// Initialize a cache given a GameInstanceManager /// diff --git a/Tests/Core/Cache.cs b/Tests/Core/Cache.cs index d93a8a06ea..aa1fb556c1 100644 --- a/Tests/Core/Cache.cs +++ b/Tests/Core/Cache.cs @@ -31,7 +31,7 @@ public void RemoveCache() cache.Dispose(); cache = null; module_cache.Dispose(); - module_cache = null; + module_cache = null; Directory.Delete(cache_dir, true); } @@ -206,6 +206,17 @@ public void ZipValid_ContainsFilenameWithBadChars_NoException() Thread.CurrentThread.CurrentUICulture = origUICulture; } + [Test] + public void ZipValid_ContainsFilenameWithUnicodeChars_Valid() + { + bool valid = false; + string reason = null; + + Assert.DoesNotThrow(() => + valid = NetFileCache.ZipValid(TestData.ZipWithUnicodeChars, out reason)); + Assert.IsTrue(valid, reason); + } + [Test] public void EnforceSizeLimit_UnderLimit_FileRetained() { diff --git a/Tests/Data/TestData.cs b/Tests/Data/TestData.cs index 88447d8339..d15615d219 100644 --- a/Tests/Data/TestData.cs +++ b/Tests/Data/TestData.cs @@ -124,6 +124,11 @@ public static string DogeCoinFlag_101_LZMA() /// public static readonly string ZipWithBadChars = DataDir("ZipWithBadChars.zip"); + /// + /// Contains files with names that differ in their Unicode and "original" representation. + /// + public static readonly string ZipWithUnicodeChars = DataDir("ZipWithUnicodeChars.zip"); + /// /// DogeCoinFlag 1.01 info. This contains a bug where the /// install stanza doesn't actually refer to any files. diff --git a/Tests/Data/ZipWithUnicodeChars.zip b/Tests/Data/ZipWithUnicodeChars.zip new file mode 100644 index 0000000000000000000000000000000000000000..d5abf6ef884f02a7799f41519cd15b5a706e3a63 GIT binary patch literal 410 zcmWIWW@Zs#00GU-jX_`rln?^a;fZ+}rTSnpJ|MBEq*y-yuHF<)y#!YEZaInR$h!2= zbgALd1=4%&-p0-QHt3a9lmvJ)GKnzYb}Pi$0uTzT%MtpqxgDY30FRrHU4hLn5K|O@ YR2m*r(0#_r2GYk2gtvh7DiDVO0P8tYqW}N^ literal 0 HcmV?d00001 diff --git a/Tests/GUI/GH1866.cs b/Tests/GUI/GH1866.cs index 8c5178f29f..91e077a615 100644 --- a/Tests/GUI/GH1866.cs +++ b/Tests/GUI/GH1866.cs @@ -15,6 +15,7 @@ namespace Tests.GUI /// which involves sorting the GUI table by Max KSP Version and then performing a repo operation. /// [TestFixture] + [NUnit.Framework.Category("Display")] public class GH1866 { private CkanModule _anyVersionModule;