Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle paths with a '?' in them #14

Merged
merged 1 commit into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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