Skip to content

Commit

Permalink
[FIXED JENKINS-26858] Quote artifact path
Browse files Browse the repository at this point in the history
  • Loading branch information
olivergondza committed Feb 10, 2015
1 parent 592f79c commit dc517d1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Expand Up @@ -44,10 +44,12 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import org.apache.tools.ant.types.selectors.SelectorUtils;

import jenkins.util.VirtualFile;

import org.apache.commons.httpclient.URIException;
import org.apache.commons.httpclient.util.URIUtil;
import org.apache.tools.ant.types.selectors.SelectorUtils;

final class ZipStorage extends VirtualFile {

static VirtualFile root(File archive) {
Expand Down Expand Up @@ -82,9 +84,11 @@ private ZipStorage(File archive, String path) {

@Override public URI toURI() {
try {
return new URI(null, path, null);
return new URI(null, URIUtil.encodePath(path), null);
} catch (URISyntaxException x) {
throw new AssertionError(x);
} catch (URIException x) {
throw new AssertionError(x);
}
}

Expand Down
Expand Up @@ -69,18 +69,25 @@ public void archiveAndRetrieve() throws Exception {

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("file.txt", artifact.getFileName());
assertEquals(7, artifact.getFileSize());
}

@Test @Bug(26858)
public void useSpecialCharsInPathName() throws Exception {
final String filename = "x:y[z].txt";

FreeStyleProject p = j.createFreeStyleProject();
p.getBuildersList().add(new WorkspaceWriter("localhost:80.txt", "content"));
p.getBuildersList().add(new WorkspaceWriter("a[b].txt", "content"));
p.getBuildersList().add(new WorkspaceWriter(filename, "content"));
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", 2, artifacts.size());
assertEquals("number of artifacts archived", 1, artifacts.size());
Run<FreeStyleProject, FreeStyleBuild>.Artifact artifact = artifacts.get(0);
assertEquals(filename, artifact.getFileName());
assertEquals(7, artifact.getFileSize());
}

// Stolen from https://github.com/jenkinsci/jenkins/commit/cb5845db29bea10afd26c4425a44bc569ee75a7a
Expand Down

0 comments on commit dc517d1

Please sign in to comment.