1
1
package software .coley .lljzip ;
2
2
3
+ import org .junit .jupiter .api .Test ;
3
4
import org .junit .jupiter .params .ParameterizedTest ;
4
5
import org .junit .jupiter .params .provider .ValueSource ;
6
+ import software .coley .lljzip .format .model .LocalFileHeader ;
5
7
import software .coley .lljzip .format .model .ZipArchive ;
8
+ import software .coley .lljzip .format .transform .IdentityZipPartMapper ;
9
+ import software .coley .lljzip .format .transform .JvmClassDirectoryMapper ;
6
10
import software .coley .lljzip .format .write .ZipOutputStreamZipWriter ;
7
11
8
12
import java .io .ByteArrayInputStream ;
14
18
import java .util .zip .ZipEntry ;
15
19
import java .util .zip .ZipInputStream ;
16
20
17
- import static org .junit .jupiter .api .Assertions .fail ;
21
+ import static org .junit .jupiter .api .Assertions .* ;
18
22
19
23
/**
20
24
* Tests for patching the <i>"trick"</i> jars, and making them compatible with standard Java ZIP apis.
@@ -43,7 +47,7 @@ public void testTrickJarPatched(String name) {
43
47
if (entry .getName ().contains ("Hello.class" )) {
44
48
byte [] buffer = new byte [1024 ];
45
49
baos = new ByteArrayOutputStream ();
46
- int len = 0 ;
50
+ int len ;
47
51
while ((len = zis .read (buffer )) > 0 )
48
52
baos .write (buffer , 0 , len );
49
53
@@ -67,7 +71,7 @@ public void testTrickJarPatched(String name) {
67
71
if (entry .getName ().contains ("Hello.class" )) {
68
72
byte [] buffer = new byte [1024 ];
69
73
baos = new ByteArrayOutputStream ();
70
- int len = 0 ;
74
+ int len ;
71
75
while ((len = zis .read (buffer )) > 0 )
72
76
baos .write (buffer , 0 , len );
73
77
@@ -81,4 +85,14 @@ public void testTrickJarPatched(String name) {
81
85
fail (ex );
82
86
}
83
87
}
88
+
89
+ @ Test
90
+ @ SuppressWarnings ("resource" )
91
+ public void testTrailingSlashTransform () {
92
+ // The 'JvmClassDirectoryMapper' maps 'Name.class/' paths to 'Name.class'
93
+ Path path = Paths .get ("src/test/resources/hello-secret-trailing-slash.jar" );
94
+ ZipArchive zip = assertDoesNotThrow (() -> ZipIO .readStandard (path )
95
+ .withMapping (new JvmClassDirectoryMapper (new IdentityZipPartMapper ())));
96
+ assertNotNull (zip .getLocalFileByName ("Hello.class" ), "Trailing slash was not patched" );
97
+ }
84
98
}
0 commit comments