Commit 0ef7941 1 parent c19f0a4 commit 0ef7941 Copy full SHA for 0ef7941
File tree 2 files changed +26
-1
lines changed
src/ICSharpCode.SharpZipLib/Core
test/ICSharpCode.SharpZipLib.Tests/Zip
2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,9 @@ public static class PathUtils
16
16
/// <returns>The path with the root removed if it was present; path otherwise.</returns>
17
17
public static string DropPathRoot ( string path )
18
18
{
19
+ // No need to drop anything
20
+ if ( path == string . Empty ) return path ;
21
+
19
22
var invalidChars = Path . GetInvalidPathChars ( ) ;
20
23
// If the first character after the root is a ':', .NET < 4.6.2 throws
21
24
var cleanRootSep = path . Length >= 3 && path [ 1 ] == ':' && path [ 2 ] == ':' ;
@@ -26,7 +29,7 @@ public static string DropPathRoot(string path)
26
29
var cleanPath = new string ( path . Take ( 258 )
27
30
. Select ( ( c , i ) => invalidChars . Contains ( c ) || ( i == 2 && cleanRootSep ) ? '_' : c ) . ToArray ( ) ) ;
28
31
29
- var stripLength = Path . GetPathRoot ( cleanPath ) . Length ;
32
+ var stripLength = Path . GetPathRoot ( cleanPath ) ? . Length ?? 0 ;
30
33
while ( path . Length > stripLength && ( path [ stripLength ] == '/' || path [ stripLength ] == '\\ ' ) ) stripLength ++ ;
31
34
return path . Substring ( stripLength ) ;
32
35
}
Original file line number Diff line number Diff line change @@ -1815,5 +1815,27 @@ public void TestDescriptorUpdateOnAdd(UseZip64 useZip64)
1815
1815
}
1816
1816
}
1817
1817
}
1818
+
1819
+ /// <summary>
1820
+ /// Check that Zip files can be created with an empty file name
1821
+ /// </summary>
1822
+ [ Test ]
1823
+ [ Category ( "Zip" ) ]
1824
+ public void HandlesEmptyFileName ( )
1825
+ {
1826
+ using var ms = new MemoryStream ( ) ;
1827
+ using ( var zos = new ZipOutputStream ( ms ) { IsStreamOwner = false } )
1828
+ {
1829
+ zos . PutNextEntry ( new ZipEntry ( String . Empty ) ) ;
1830
+ Utils . WriteDummyData ( zos , 64 ) ;
1831
+ }
1832
+ ms . Seek ( 0 , SeekOrigin . Begin ) ;
1833
+ using ( var zis = new ZipInputStream ( ms ) { IsStreamOwner = false } )
1834
+ {
1835
+ var entry = zis . GetNextEntry ( ) ;
1836
+ Assert . That ( entry . Name , Is . Empty ) ;
1837
+ Assert . That ( zis . ReadBytes ( 64 ) . Length , Is . EqualTo ( 64 ) ) ;
1838
+ }
1839
+ }
1818
1840
}
1819
1841
}
You can’t perform that action at this time.
0 commit comments