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 c86869d08..01d382018 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 @@ -484,6 +484,17 @@ public class URIishTest { assertEquals("c", humanishName); } + @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"; 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 8c7bedc6f..1c9397922 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];