Skip to content

Commit 84a78c0

Browse files
committed
Rewrite how unpackFromJarURL gets the list of entries (possibly more than 2) and use them
1 parent 07d64a1 commit 84a78c0

File tree

1 file changed

+46
-24
lines changed

1 file changed

+46
-24
lines changed

src/main/java/io/vertx/core/file/impl/FileResolverImpl.java

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
import java.io.IOException;
2222
import java.io.InputStream;
2323
import java.net.URL;
24+
import java.util.ArrayList;
2425
import java.util.Enumeration;
26+
import java.util.List;
2527
import java.util.zip.ZipEntry;
2628
import java.util.zip.ZipFile;
2729

@@ -275,34 +277,54 @@ private File unpackFromFileURL(URL url, String fileName, ClassLoader cl) {
275277
return cacheFile;
276278
}
277279

280+
/**
281+
* Parse the list of entries of a URL assuming the URL is a jar URL.
282+
*
283+
* <ul>
284+
* <li>when the URL is a nested file within the archive, the list is the jar entry</li>
285+
* <li>when the URL is a nested file within a nested file within the archive, the list is jar entry followed by the jar entry of the nested archive</li>
286+
* <li>and so on.</li>
287+
* </ul>
288+
*
289+
* @param url the URL
290+
* @return the list of entries
291+
*/
292+
private List<String> listOfEntries(URL url) {
293+
String path = url.getPath();
294+
List<String> list = new ArrayList<>();
295+
int last = path.length();
296+
for (int i = path.length() - 1; i > 4;) {
297+
if (path.charAt(i) == '!' && (path.startsWith(".jar", i - 4) || path.startsWith(".zip", i - 4) || path.startsWith(".war", i - 4))) {
298+
list.add(path.substring(2 + i, last));
299+
last = i;
300+
i -= 4;
301+
} else {
302+
i--;
303+
}
304+
}
305+
return list;
306+
}
307+
308+
278309
private File unpackFromJarURL(URL url, String fileName) {
279310
ZipFile zip = null;
280311
try {
281-
String path = url.getPath();
282-
int idx1 = -1, idx2 = -1;
283-
for (int i = path.length() - 1; i > 4; ) {
284-
if (path.charAt(i) == '!' && (path.startsWith(".jar", i - 4) || path.startsWith(".zip", i - 4) || path.startsWith(".war", i - 4))) {
285-
if (idx1 == -1) {
286-
idx1 = i;
287-
i -= 4;
288-
continue;
289-
} else {
290-
idx2 = i;
291-
break;
292-
}
293-
}
294-
i--;
295-
}
296-
if (idx2 == -1) {
297-
File file = new File(decodeURIComponent(path.substring(5, idx1), false));
298-
zip = new ZipFile(file);
299-
} else {
300-
String s = path.substring(idx2 + 2, idx1);
301-
File file = resolveFile(s);
302-
zip = new ZipFile(file);
312+
List<String> listOfEntries = listOfEntries(url);
313+
switch (listOfEntries.size()) {
314+
case 1:
315+
String path = url.getPath();
316+
int to = path.length() - listOfEntries.get(0).length() - 2;
317+
String sub = path.substring(5, to);
318+
File file = new File(decodeURIComponent(sub, false));
319+
zip = new ZipFile(file);
320+
break;
321+
case 2:
322+
zip = new ZipFile(resolveFile(listOfEntries.get(1)));
323+
break;
324+
default:
325+
throw new UnsupportedOperationException("Not yet implemented");
303326
}
304-
305-
String inJarPath = path.substring(idx1 + 2);
327+
String inJarPath = listOfEntries.get(0);
306328
StringBuilder prefixBuilder = new StringBuilder();
307329
int first = 0;
308330
int second;

0 commit comments

Comments
 (0)