Browse Source

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>
stable-1.0
Stefan Lay 14 years ago
parent
commit
05bb92980b
  1. 11
      org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java
  2. 8
      org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java

11
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java

@ -484,6 +484,17 @@ public class URIishTest {
assertEquals("c", humanishName); 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 @Test
public void testUserPasswordAndPort() throws URISyntaxException { public void testUserPasswordAndPort() throws URISyntaxException {
String str = "http://user:secret@host.xy:80/some/path"; String str = "http://user:secret@host.xy:80/some/path";

8
org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java

@ -46,6 +46,7 @@
package org.eclipse.jgit.transport; package org.eclipse.jgit.transport;
import java.io.File;
import java.io.Serializable; import java.io.Serializable;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
@ -551,7 +552,12 @@ public class URIish implements Serializable {
public String getHumanishName() throws IllegalArgumentException { public String getHumanishName() throws IllegalArgumentException {
if ("".equals(getPath()) || getPath() == null) if ("".equals(getPath()) || getPath() == null)
throw new IllegalArgumentException(); 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) if (elements.length == 0)
throw new IllegalArgumentException(); throw new IllegalArgumentException();
String result = elements[elements.length - 1]; String result = elements[elements.length - 1];

Loading…
Cancel
Save