Merge pull request #541 from avao/master

UT and Fix for: Index out of range exception from gzip #532
This commit is contained in:
Adam Hathcock
2020-10-19 12:33:31 +01:00
committed by GitHub
2 changed files with 14 additions and 10 deletions

View File

@@ -384,16 +384,7 @@ namespace SharpCompress.Compressors.Deflate
if (_fileName.Contains("\\"))
{
// trim any leading path
int length = _fileName.Length;
int num = length;
while (--num >= 0)
{
char c = _fileName[num];
if (c == '\\')
{
_fileName = _fileName.Substring(num + 1, length - num - 1);
}
}
_fileName = Path.GetFileName(_fileName);
}
}
}

View File

@@ -49,5 +49,18 @@ namespace SharpCompress.Test.GZip
}
});
}
[Fact]
public void GZip_Writer_Entry_Path_With_Dir()
{
using (Stream stream = File.Open(Path.Combine(SCRATCH_FILES_PATH, "Tar.tar.gz"), FileMode.OpenOrCreate, FileAccess.Write))
using (var writer = new GZipWriter(stream))
{
var path = Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar");
writer.Write(path, path); //covers issue #532
}
CompareArchivesByPath(Path.Combine(SCRATCH_FILES_PATH, "Tar.tar.gz"),
Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar.gz"));
}
}
}