]> source.dussan.org Git - jgit.git/commitdiff
URIish: fixed full uri pattern not expecting end of line after host name 96/61596/3
authorAndrey Loskutov <loskutov@gmx.de>
Mon, 30 Nov 2015 21:48:13 +0000 (22:48 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Fri, 11 Dec 2015 23:55:31 +0000 (00:55 +0100)
Bug: 483326
Change-Id: I8b6e3eb648c8ec2c38f73de22382537b1276b779
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java

index 745c3220133786d6a6f9674bc3bfa1978aec3a68..76eb18afdf1aa12cee387a652e27c8ddbb937580 100644 (file)
@@ -928,4 +928,19 @@ public class URIishTest {
                        }
                }
        }
+
+       @Test
+       public void testStringConstructor() throws Exception {
+               String str = "http://example.com/";
+               URIish u = new URIish(str);
+               assertEquals("example.com", u.getHost());
+               assertEquals("/", u.getPath());
+               assertEquals(str, u.toString());
+
+               str = "http://example.com";
+               u = new URIish(str);
+               assertEquals("example.com", u.getHost());
+               assertEquals("", u.getPath());
+               assertEquals(str, u.toString());
+       }
 }
index 3c22b1cad6400649450efecbf99996a3491a60fa..9aeb840ebe2e794846e43b2df39a4d943b287cf1 100644 (file)
@@ -137,7 +137,11 @@ public class URIish implements Serializable {
                        + OPT_PORT_P //
                        + "(" // open a group capturing the user-home-dir-part //$NON-NLS-1$
                        + (USER_HOME_P + "?") //$NON-NLS-1$
-                       + "[\\\\/])" //$NON-NLS-1$
+                       + "(?:" // start non capturing group for host //$NON-NLS-1$
+                                       // separator or end of line
+                       + "[\\\\/])|$" //$NON-NLS-1$
+                       + ")" // close non capturing group for the host//$NON-NLS-1$
+                                       // separator or end of line
                        + ")?" // close the optional group containing hostname //$NON-NLS-1$
                        + "(.+)?" //$NON-NLS-1$
                        + "$"); //$NON-NLS-1$
@@ -640,7 +644,7 @@ public class URIish implements Serializable {
 
                if (getPath() != null) {
                        if (getScheme() != null) {
-                               if (!getPath().startsWith("/")) //$NON-NLS-1$
+                               if (!getPath().startsWith("/") && !getPath().isEmpty()) //$NON-NLS-1$
                                        r.append('/');
                        } else if (getHost() != null)
                                r.append(':');
@@ -711,9 +715,9 @@ public class URIish implements Serializable {
         */
        public String getHumanishName() throws IllegalArgumentException {
                String s = getPath();
-               if ("/".equals(s)) //$NON-NLS-1$
+               if ("/".equals(s) || "".equals(s)) //$NON-NLS-1$
                        s = getHost();
-               if ("".equals(s) || s == null) //$NON-NLS-1$
+               if (s == null) // $NON-NLS-1$
                        throw new IllegalArgumentException();
 
                String[] elements;