diff options
author | Stefan Lay <stefan.lay@sap.com> | 2011-05-06 10:42:51 +0200 |
---|---|---|
committer | Stefan Lay <stefan.lay@sap.com> | 2011-05-06 10:42:51 +0200 |
commit | 05bb92980b27cf8379e6a39f993ae21952ffe05d (patch) | |
tree | c51ef65c3388543eaa1ec70b98fdf1ea155ba9b9 | |
parent | b8fdda11cc4a786c24ba309ec755321dba6d9955 (diff) | |
download | jgit-05bb92980b27cf8379e6a39f993ae21952ffe05d.tar.gz jgit-05bb92980b27cf8379e6a39f993ae21952ffe05d.zip |
Fix getHumanishName broken for windows paths
Since d1718a the method getHumanishName was broken on windows since
the URIish is not normalized anymore. For a path like
"C:\gitRepositories\egit" the whole path was returned instead of
"egit".
Bug: 343519
Change-Id: I95056009072b99d32f288966302d0f8188b47836
Signed-off-by: Stefan Lay <stefan.lay@sap.com>
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java | 11 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java | 8 |
2 files changed, 18 insertions, 1 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java index c86869d088..01d3820184 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java @@ -485,6 +485,17 @@ public class URIishTest { } @Test + public void testGetWindowsPathHumanishName() + throws IllegalArgumentException, + URISyntaxException { + if (File.separatorChar == '\\') { + String humanishName = new URIish("file:///C\\a\\b\\c.git/") + .getHumanishName(); + assertEquals("c", humanishName); + } + } + + @Test public void testUserPasswordAndPort() throws URISyntaxException { String str = "http://user:secret@host.xy:80/some/path"; URIish u = new URIish(str); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java index 8c7bedc6fc..1c9397922a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java @@ -46,6 +46,7 @@ package org.eclipse.jgit.transport; +import java.io.File; import java.io.Serializable; import java.net.URISyntaxException; import java.net.URL; @@ -551,7 +552,12 @@ public class URIish implements Serializable { public String getHumanishName() throws IllegalArgumentException { if ("".equals(getPath()) || getPath() == null) throw new IllegalArgumentException(); - String[] elements = getPath().split("/"); + String s = getPath(); + String[] elements; + if ("file".equals(scheme) || LOCAL_FILE.matcher(s).matches()) + elements = s.split("[\\" + File.separatorChar + "/]"); + else + elements = s.split("/"); if (elements.length == 0) throw new IllegalArgumentException(); String result = elements[elements.length - 1]; |