Fix retrieval of test resources for paths containing spaces
PATCH 1/3 Fix retrieval of test resources for paths containing spaces
The use of URL.getPath() can be problematic when the repository path contains spaces since they get encoded as %20, which will lead to a "No such file" error when resolving to a local file. The fix first tries to convert the resource URL to a URI (added in Java 1.5), which is then used to construct the File instance. As a fallback use the old behavior if a URISyntaxException is thrown.
Signed-off-by Jonas Fonseca <[email protected]>
--- .../tst/org/spearce/jgit/util/JGitTestUtil.java | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
org.spearce.jgit.test/tst/org/spearce/jgit/util/JGitTestUtil.java +6 -1
@@ -38,6 +38,7 @@ package org.spearce.jgit.util; import java.io.File; +import java.net.URISyntaxException; import java.net.URL; public abstract class JGitTestUtil {
@@ -57,7 +58,11 @@ public static File getTestResourceFile(final String fileName) { // loaded previously return new File("tst", fileName); } - return new File(url.getPath()); + try { + return new File(url.toURI()); + } catch(URISyntaxException e) { + return new File(url.getPath()); + } } private static ClassLoader cl() {
Signature · 4 lines
1.6.0.2.1166.g8d97a.dirty -- Jonas Fonseca