Skip to content

Commit

Permalink
Merge pull request #14 from stuartwdouglas/question-mark
Browse files Browse the repository at this point in the history
Handle paths with a '?' in them
  • Loading branch information
aloubyansky authored Feb 15, 2022
2 parents 81c6411 + ed472ac commit bb9f681
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/io/quarkus/fs/util/ZipUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.DirectoryStream;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.FileSystem;
Expand Down Expand Up @@ -65,7 +66,7 @@ public static void unzip(Path zipFile, Path targetDir) throws IOException {
public static URI toZipUri(Path zipFile) throws IOException {
URI zipUri = zipFile.toUri();
try {
zipUri = new URI(JAR_URI_PREFIX + zipUri.getScheme(), zipUri.getPath(), null);
zipUri = new URL(JAR_URI_PREFIX + zipUri.getScheme() + "://" + zipUri.getRawPath() + "!/").toURI();
} catch (URISyntaxException e) {
throw new IOException("Failed to create a JAR URI for " + zipFile, e);
}
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/io/quarkus/fs/util/ZipUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.util.Collections;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;

class ZipUtilsTest {

Expand Down Expand Up @@ -74,6 +76,32 @@ public void testNewZip() throws Exception {
}
}

/**
* Test that the {@link ZipUtils#newZip(Path)} works as expected when the path contains a question mark
*
* Windows does not support question marks in file names
*
* @throws Exception
*/
@Test
@DisabledOnOs(OS.WINDOWS)
public void testNewZipWithQuestionMark() throws Exception {
final Path tmpDir = Paths.get(System.getProperty("java.io.tmpdir"));
final Path zipPath = Paths.get(tmpDir.toString(), "ziputils?test-" + System.currentTimeMillis() + ".jar");
try {
try (final FileSystem fs = ZipUtils.newZip(zipPath)) {
final Path someFileInZip = fs.getPath("hello.txt");
Files.write(someFileInZip, "hello".getBytes(StandardCharsets.UTF_8));
}
// now just verify that the content was actually written out
try (final FileSystem fs = ZipUtils.newFileSystem(zipPath)) {
assertFileExistsWithContent(fs.getPath("hello.txt"), "hello");
}
} finally {
Files.deleteIfExists(zipPath);
}
}

/**
* Tests that the {@link ZipUtils#newZip(Path)} works correctly, and creates the zip file,
* when the parent directories of the {@link Path} passed to it are not present.
Expand Down

0 comments on commit bb9f681

Please sign in to comment.