]> source.dussan.org Git - jgit.git/commitdiff
Fix getHumanishName broken for windows paths 98/3198/6
authorStefan Lay <stefan.lay@sap.com>
Fri, 6 May 2011 08:42:51 +0000 (10:42 +0200)
committerStefan Lay <stefan.lay@sap.com>
Fri, 6 May 2011 08:42:51 +0000 (10:42 +0200)
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>
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java

index c86869d088eedfe0db489fdec41ba3d24089eaf8..01d3820184ded79da0e0043c937e721f90d32243 100644 (file)
@@ -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";
index 8c7bedc6fcbc13911fda04a0d62df0e4ac08534f..1c9397922afcbc4d19719a7bcdd3b0dc47129dcd 100644 (file)
@@ -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];