aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--netx/net/sourceforge/jnlp/cache/ResourceTracker.java5
-rw-r--r--netx/net/sourceforge/jnlp/util/UrlUtils.java5
-rw-r--r--tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java20
4 files changed, 33 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 331a857..caf00d8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2013-04-26 Adam Domurad <[email protected]>
+
+ * netx/net/sourceforge/jnlp/cache/ResourceTracker.java
+ (getCacheFile): Use decodeUrlAsFile instead of toURI().getPath().
+ * netx/net/sourceforge/jnlp/util/UrlUtils.java
+ (decodeUrlAsFile): New, tolerates ill-formed URLs.
+ * tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java:
+ (testDecodeUrlAsFile): Test for (decodeUrlAsFile)
+
2013-04-26 Jiri Vanek <[email protected]>
Jacob Wisor <[email protected]>
diff --git a/netx/net/sourceforge/jnlp/cache/ResourceTracker.java b/netx/net/sourceforge/jnlp/cache/ResourceTracker.java
index dffbb3b..7b6a772 100644
--- a/netx/net/sourceforge/jnlp/cache/ResourceTracker.java
+++ b/netx/net/sourceforge/jnlp/cache/ResourceTracker.java
@@ -390,7 +390,7 @@ public class ResourceTracker {
return resource.localFile;
if (location.getProtocol().equalsIgnoreCase("file")) {
- File file = new File(location.toURI().getPath());
+ File file = UrlUtils.decodeUrlAsFile(location);
if (file.exists())
return file;
}
@@ -401,9 +401,6 @@ public class ResourceTracker {
ex.printStackTrace();
return null; // need an error exception to throw
- } catch (URISyntaxException e) {
- e.printStackTrace();
- return null;
}
}
diff --git a/netx/net/sourceforge/jnlp/util/UrlUtils.java b/netx/net/sourceforge/jnlp/util/UrlUtils.java
index d9d6866..af36a9c 100644
--- a/netx/net/sourceforge/jnlp/util/UrlUtils.java
+++ b/netx/net/sourceforge/jnlp/util/UrlUtils.java
@@ -37,6 +37,7 @@ exception statement from your version.
package net.sourceforge.jnlp.util;
+import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
@@ -134,4 +135,8 @@ public class UrlUtils {
return normalizeUrlQuietly(url, false);
}
+ /* Decode a URL as a file, being tolerant of URLs with mixed encoded & decoded portions. */
+ public static File decodeUrlAsFile(URL url) {
+ return new File(decodeUrlQuietly(url).getFile());
+ }
}
diff --git a/tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java b/tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java
index 1a0e69c..251dfb2 100644
--- a/tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java
+++ b/tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java
@@ -1,9 +1,11 @@
package net.sourceforge.jnlp.util;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import java.io.File;
import java.net.URL;
-
+
import org.junit.Test;
public class UrlUtilsTest {
@@ -57,10 +59,24 @@ public class UrlUtilsTest {
assertEquals("file://example/%20test",
UrlUtils.normalizeUrl(new URL("file://example/ test"), true).toString());
}
+
@Test
public void testNormalizeUrlQuietly() throws Exception {
// This is a wrapper over UrlUtils.normalizeUrl(), simple test suffices
assertEquals("http://example.com/%20test%20test",
UrlUtils.normalizeUrl(new URL("http://example.com/ test%20test ")).toString());
}
+
+ @Test
+ public void testDecodeUrlAsFile() throws Exception {
+ String[] testPaths = {"/simple", "/ with spaces", "/with /multiple=/ odd characters?"};
+
+ for (String testPath : testPaths) {
+ File testFile = new File(testPath);
+ URL notEncodedUrl = testFile.toURL();
+ URL encodedUrl = testFile.toURI().toURL();
+ assertEquals(testFile, UrlUtils.decodeUrlAsFile(notEncodedUrl));
+ assertEquals(testFile, UrlUtils.decodeUrlAsFile(encodedUrl));
+ }
+ }
} \ No newline at end of file