Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-26858] Always use scheme when constructing URI for arc…
…hived file
  • Loading branch information
olivergondza committed Mar 22, 2017
1 parent 49f4422 commit c0c641d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Expand Up @@ -94,7 +94,9 @@ private ZipStorage(File archive, String path) {

@Override public URI toURI() {
try {
return new URI(null, URIUtil.encodePath(path), null);
// If no scheme is provided, beginning of the path is parsed as the scheme causing validation problems.
// Using some scheme to workaround that + prepending prefix to avoid empty URI path.
return new URI("zip", "./" + URIUtil.encodePath(path), null);
} catch (URISyntaxException x) {
throw new AssertionError(x);
} catch (URIException x) {
Expand Down Expand Up @@ -187,7 +189,8 @@ private boolean looksLikeDir() {
ZipEntry entry = entries.nextElement();
String p = entry.getName();
if (p.startsWith(path)) {
files.add(new ZipStorage(archive, path + p.substring(path.length()).replaceFirst("/.+", "/")));
String pth = path + p.substring(path.length()).replaceFirst("/.+", "/");
files.add(new ZipStorage(archive, pth));
}
}
return files.toArray(new VirtualFile[files.size()]);
Expand Down
Expand Up @@ -101,17 +101,17 @@ public void archiveAndRetrieve() throws Exception {

@Test @Issue("JENKINS-26858")
public void useSpecialCharsInPathName() throws Exception {
final String filename = "x:y[z].txt";
final String filename = "2017-03-21_04:25:03/x:y[z].txt";

FreeStyleProject p = j.createFreeStyleProject();
p.getBuildersList().add(new WorkspaceWriter(filename, "content"));
p.getPublishersList().add(new ArtifactArchiver("*", null, false));
p.getPublishersList().add(new ArtifactArchiver("**/*", null, false));
FreeStyleBuild build = j.buildAndAssertSuccess(p);

List<Run<FreeStyleProject, FreeStyleBuild>.Artifact> artifacts = build.getArtifacts();
assertEquals("number of artifacts archived", 1, artifacts.size());
Run<FreeStyleProject, FreeStyleBuild>.Artifact artifact = artifacts.get(0);
assertEquals(filename, artifact.getFileName());
assertEquals(filename, artifact.relativePath);
assertEquals(7, artifact.getFileSize());
}

Expand Down
Expand Up @@ -95,6 +95,7 @@ public class ZipStorageTest {
private void doBasics(VirtualFile vf) throws Exception {
assertTrue(vf.isDirectory());
assertTrue(vf.exists());
vf.toURI(); // No Exception

VirtualFile[] list = vf.list();
Arrays.sort(list);
Expand All @@ -103,6 +104,7 @@ private void doBasics(VirtualFile vf) throws Exception {
assertEquals("dir", dir.getName());
assertTrue(dir.isDirectory());
assertFalse(dir.isFile());
vf.toURI(); // No Exception
assertFalse(vf.child("dir").isFile());
assertTrue(dir.exists());
assertEquals(vf, dir.getParent());
Expand Down

0 comments on commit c0c641d

Please sign in to comment.