Browse Source

URIish: fixed full uri pattern not expecting end of line after host name

Bug: 483326
Change-Id: I8b6e3eb648c8ec2c38f73de22382537b1276b779
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
tags/v4.2.0.201601211800-r
Andrey Loskutov 8 years ago
parent
commit
85d09a9ec7

+ 15
- 0
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java View File

} }
} }
} }

@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());
}
} }

+ 8
- 4
org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java View File

+ OPT_PORT_P // + OPT_PORT_P //
+ "(" // open a group capturing the user-home-dir-part //$NON-NLS-1$ + "(" // open a group capturing the user-home-dir-part //$NON-NLS-1$
+ (USER_HOME_P + "?") //$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$ + ")?" // close the optional group containing hostname //$NON-NLS-1$
+ "(.+)?" //$NON-NLS-1$ + "(.+)?" //$NON-NLS-1$
+ "$"); //$NON-NLS-1$ + "$"); //$NON-NLS-1$


if (getPath() != null) { if (getPath() != null) {
if (getScheme() != null) { if (getScheme() != null) {
if (!getPath().startsWith("/")) //$NON-NLS-1$
if (!getPath().startsWith("/") && !getPath().isEmpty()) //$NON-NLS-1$
r.append('/'); r.append('/');
} else if (getHost() != null) } else if (getHost() != null)
r.append(':'); r.append(':');
*/ */
public String getHumanishName() throws IllegalArgumentException { public String getHumanishName() throws IllegalArgumentException {
String s = getPath(); String s = getPath();
if ("/".equals(s)) //$NON-NLS-1$
if ("/".equals(s) || "".equals(s)) //$NON-NLS-1$
s = getHost(); s = getHost();
if ("".equals(s) || s == null) //$NON-NLS-1$
if (s == null) // $NON-NLS-1$
throw new IllegalArgumentException(); throw new IllegalArgumentException();


String[] elements; String[] elements;

Loading…
Cancel
Save