diff --git a/src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs b/src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs index 730d8e48c..d5105b5ab 100644 --- a/src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs +++ b/src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs @@ -211,7 +211,7 @@ internal ZipEntry(string name, int versionRequiredToExtract, int madeByInfo, } this.DateTime = DateTime.Now; - this.name = CleanName(name); + this.name = name; this.versionMadeBy = (ushort)madeByInfo; this.versionToExtract = (ushort)versionRequiredToExtract; this.method = method; diff --git a/test/ICSharpCode.SharpZipLib.Tests/Zip/StreamHandling.cs b/test/ICSharpCode.SharpZipLib.Tests/Zip/StreamHandling.cs index a2a9f635b..32920503e 100644 --- a/test/ICSharpCode.SharpZipLib.Tests/Zip/StreamHandling.cs +++ b/test/ICSharpCode.SharpZipLib.Tests/Zip/StreamHandling.cs @@ -352,5 +352,34 @@ public void ShouldReadBZip2EntryButNotDecompress() Assert.Throws(() => zis.Read(buffer, 0, 1), "Trying to read the stream should throw"); } } + + /// + /// Test for https://github.com/icsharpcode/SharpZipLib/issues/341 + /// Should be able to read entries whose names contain invalid filesystem + /// characters + /// + [Test] + [Category("Zip")] + public void ShouldBeAbleToReadEntriesWithInvalidFileNames() + { + var testFileName = ".txt"; + + using (var memoryStream = new MemoryStream()) + { + using (var outStream = new ZipOutputStream(memoryStream)) + { + outStream.IsStreamOwner = false; + outStream.PutNextEntry(new ZipEntry(testFileName)); + } + + memoryStream.Seek(0, SeekOrigin.Begin); + + using (var inStream = new ZipInputStream(memoryStream)) + { + var entry = inStream.GetNextEntry(); + Assert.That(entry.Name, Is.EqualTo(testFileName), "output name must match original name"); + } + } + } } }