From 6b9db3b5496e986d9cbe16f94d65c6bb49aa6df7 Mon Sep 17 00:00:00 2001 From: Adam Domurad Date: Wed, 5 Jun 2013 15:12:01 -0400 Subject: Fix PR1465 - java.io.FileNotFoundException while trying to download a JAR file --- netx/net/sourceforge/jnlp/util/UrlUtils.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'netx/net/sourceforge') diff --git a/netx/net/sourceforge/jnlp/util/UrlUtils.java b/netx/net/sourceforge/jnlp/util/UrlUtils.java index af36a9c..73d896a 100644 --- a/netx/net/sourceforge/jnlp/util/UrlUtils.java +++ b/netx/net/sourceforge/jnlp/util/UrlUtils.java @@ -86,16 +86,29 @@ public class UrlUtils { } } + /* Use the URI syntax check of 'toURI' to see if it matches RFC2396. + * See http://www.ietf.org/rfc/rfc2396.txt */ + public static boolean isValidRFC2396Url(URL url) { + try { + url.toURI(); + return true; + } catch (URISyntaxException e) { + return false; + } + } + /* Ensure a URL is properly percent-encoded. * Certain usages require local-file URLs to be encoded, eg for code-base & document-base. */ public static URL normalizeUrl(URL url, boolean encodeFileUrls) throws MalformedURLException, UnsupportedEncodingException, URISyntaxException { if (url == null) { return null; } + String protocol = url.getProtocol(); boolean shouldEncode = (encodeFileUrls || !"file".equals(protocol)); - if (protocol == null || !shouldEncode || url.getPath() == null) { + // PR1465: We should not call 'URLDecoder.decode' on RFC2396-compliant URLs + if (protocol == null || !shouldEncode || url.getPath() == null || isValidRFC2396Url(url)) { return url; } -- cgit v1.2.3