[Arakhnę-Dev] [192] * Bug fix: URL decoding should not be invoked on null value.

[ Thread Index | Date Index | More arakhne.org/dev Archives ]


Revision: 192
Author:   galland
Date:     2010-10-05 18:59:30 +0200 (Tue, 05 Oct 2010)
Log Message:
-----------
* Bug fix: URL decoding should not be invoked on null value.

Modified Paths:
--------------
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java

Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java	2010-10-04 12:34:16 UTC (rev 191)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java	2010-10-05 16:59:30 UTC (rev 192)
@@ -108,6 +108,17 @@
 	/** Prefix used to join in a Jar URL the jar filename and the inside-jar filename.
 	 */
 	public static final String JAR_URL_FILE_ROOT = "!/"; //$NON-NLS-1$
+	
+	/** Decode the given string.
+	 * 
+	 * @param s
+	 * @return decoded string or <var>s/<var>.
+	 * @throws UnsupportedEncodingException 
+	 */
+	private static String decodeURL(String s) throws UnsupportedEncodingException {
+		if (s==null) return null;
+		return URLDecoder.decode(s, Charset.defaultCharset().displayName());
+	}
 
 	/** Replies if the given URL has a jar scheme.
 	 * 
@@ -317,9 +328,7 @@
 			if (prefix!=null) {
 				return toJarURL(prefix, path);
 			}
-			if (path!=null) {
-				path = URLDecoder.decode(path, Charset.defaultCharset().displayName());
-			}
+			path = decodeURL(path);
 			URI uri = new URI(
 					filename.getProtocol(), 
 					filename.getUserInfo(), 
@@ -736,8 +745,8 @@
 					urlBase.getUserInfo(), 
 					urlBase.getHost(), 
 					urlBase.getPort(), 
-					URLDecoder.decode(buf.toString(), Charset.defaultCharset().displayName()),
-					URLDecoder.decode(urlBase.getQuery(), Charset.defaultCharset().displayName()),
+					decodeURL(buf.toString()),
+					decodeURL(urlBase.getQuery()),
 					urlBase.getRef());
 			return uri.toURL();
 		}
@@ -785,8 +794,8 @@
 					urlBase.getUserInfo(), 
 					urlBase.getHost(), 
 					urlBase.getPort(), 
-					URLDecoder.decode(buf.toString(), Charset.defaultCharset().displayName()),
-					URLDecoder.decode(urlBase.getQuery(), Charset.defaultCharset().displayName()),
+					decodeURL(buf.toString()),
+					decodeURL(urlBase.getQuery()),
 					urlBase.getRef());
 			return uri.toURL();
 		}
@@ -887,8 +896,8 @@
 					filename.getUserInfo(), 
 					filename.getHost(), 
 					filename.getPort(), 
-					URLDecoder.decode(buf.toString(), Charset.defaultCharset().displayName()),
-					URLDecoder.decode(filename.getQuery(), Charset.defaultCharset().displayName()),
+					decodeURL(buf.toString()),
+					decodeURL(filename.getQuery()),
 					filename.getRef());
 			return uri.toURL();
 		}
@@ -967,8 +976,8 @@
 					filename.getUserInfo(), 
 					filename.getHost(), 
 					filename.getPort(), 
-					URLDecoder.decode(buf.toString(), Charset.defaultCharset().displayName()),
-					URLDecoder.decode(filename.getQuery(), Charset.defaultCharset().displayName()),
+					decodeURL(buf.toString()),
+					decodeURL(filename.getQuery()),
 					filename.getRef());
 			return uri.toURL();
 		}
@@ -1313,8 +1322,8 @@
 			try {
 				uri = new URI(url.getProtocol(), url.getUserInfo(), url
 						.getHost(), url.getPort(), 
-						URLDecoder.decode(url.getPath(), Charset.defaultCharset().displayName()),
-						URLDecoder.decode(url.getQuery(), Charset.defaultCharset().displayName()),
+						decodeURL(url.getPath()),
+						decodeURL(url.getQuery()),
 						url.getRef());
 			}
 			catch(UnsupportedEncodingException e1) {


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/