diff --git a/src/ICSharpCode.SharpZipLib/Tar/TarStringExtension.cs b/src/ICSharpCode.SharpZipLib/Tar/TarStringExtension.cs index b5506c189..8244bb6d4 100644 --- a/src/ICSharpCode.SharpZipLib/Tar/TarStringExtension.cs +++ b/src/ICSharpCode.SharpZipLib/Tar/TarStringExtension.cs @@ -6,9 +6,10 @@ internal static class TarStringExtension { public static string ClearTarPath(this string s) { - if (Path.GetPathRoot(s) != null) + var pathRoot = Path.GetPathRoot(s); + if (!string.IsNullOrEmpty(pathRoot)) { - s = s.Substring(Path.GetPathRoot(s).Length); + s = s.Substring(pathRoot.Length); } return s.Replace(Path.DirectorySeparatorChar, '/'); } diff --git a/test/ICSharpCode.SharpZipLib.Tests/Tar/TarTests.cs b/test/ICSharpCode.SharpZipLib.Tests/Tar/TarTests.cs index 80f762bdd..da4427d02 100644 --- a/test/ICSharpCode.SharpZipLib.Tests/Tar/TarTests.cs +++ b/test/ICSharpCode.SharpZipLib.Tests/Tar/TarTests.cs @@ -944,7 +944,7 @@ public void rootPathIsRespected() var expectationDirectory = new DirectoryInfo(tempDirectory); foreach (var checkFile in expectationDirectory.GetFiles("", SearchOption.AllDirectories)) { - var relativePath = expectationDirectory.FullName.Substring(expectationDirectory.FullName.Length); + var relativePath = checkFile.FullName.Substring(expectationDirectory.FullName.Length + 1); FileAssert.Exists(Path.Combine(extractDirectory, relativePath)); FileAssert.AreEqual(checkFile.FullName, Path.Combine(extractDirectory, relativePath)); } @@ -954,7 +954,7 @@ private void CreateAndClearDirectory(string path) { if (Directory.Exists(path)) { - Directory.Delete(path); + Directory.Delete(path, true); } Directory.CreateDirectory(path); }