From 55a287b9ad8a5cdf358ba76aaeefa714b9f47af4 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Sat, 5 Apr 2008 01:11:48 +0000 Subject: [PATCH] [fixed] Perform RFC2396 style escape. I suppose the proper fix is to change the signature to return URI so that it works better with chaining (issue #1464) git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@8281 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/main/java/hudson/Util.java | 19 +++++++++++++++++++ .../hudson/maven/reporters/MavenArtifact.java | 2 +- .../main/java/hudson/model/AbstractItem.java | 3 ++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/hudson/Util.java b/core/src/main/java/hudson/Util.java index 9025a6d70c..4f5c8139be 100644 --- a/core/src/main/java/hudson/Util.java +++ b/core/src/main/java/hudson/Util.java @@ -27,6 +27,8 @@ import java.io.Writer; import java.io.PrintStream; import java.net.InetAddress; import java.net.UnknownHostException; +import java.net.URI; +import java.net.URISyntaxException; import java.security.DigestInputStream; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -696,6 +698,23 @@ public class Util { } } + /** + * Encodes the URL by RFC 2396. + * + * I thought there's another spec that refers to UTF-8 as the encoding, + * but don't remember it right now. + * + * @since 1.204 + */ + public static String encodeRFC2396(String url) { + try { + return new URI(null,url,null).toASCIIString(); + } catch (URISyntaxException e) { + LOGGER.warning("Failed to encode "+url); // could this ever happen? + return url; + } + } + /** * Wraps with the error icon and the CSS class to render error message. * @since 1.173 diff --git a/core/src/main/java/hudson/maven/reporters/MavenArtifact.java b/core/src/main/java/hudson/maven/reporters/MavenArtifact.java index 0a2b8585ed..82ed67f4e3 100644 --- a/core/src/main/java/hudson/maven/reporters/MavenArtifact.java +++ b/core/src/main/java/hudson/maven/reporters/MavenArtifact.java @@ -156,8 +156,8 @@ public final class MavenArtifact implements Serializable { * Called from within Maven to archive an artifact in Hudson. */ public void archive(MavenBuildProxy build, File file, BuildListener listener) throws IOException, InterruptedException { - listener.getLogger().println("[HUDSON] Archiving "+ file); FilePath target = getArtifactArchivePath(build,groupId,artifactId,version); + listener.getLogger().println("[HUDSON] Archiving "+ file+" to "+target); new FilePath(file).copyTo(target); /* debug probe to investigate "missing artifact" problem typically seen like this: diff --git a/core/src/main/java/hudson/model/AbstractItem.java b/core/src/main/java/hudson/model/AbstractItem.java index 54228ca42a..4ce5c121d8 100644 --- a/core/src/main/java/hudson/model/AbstractItem.java +++ b/core/src/main/java/hudson/model/AbstractItem.java @@ -12,6 +12,7 @@ import org.kohsuke.stapler.export.ExportedBean; import java.io.File; import java.io.IOException; import java.util.Collection; +import java.net.URI; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; @@ -150,7 +151,7 @@ public abstract class AbstractItem extends Actionable implements Item { StaplerRequest request = Stapler.getCurrentRequest(); if(request==null) throw new IllegalStateException("Not processing a HTTP request"); - return request.getRootPath()+'/'+getUrl(); + return Util.encodeRFC2396(request.getRootPath()+'/'+getUrl()); } /** -- GitLab