aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-11-09 14:36:01 -0800
committerShawn O. Pearce <spearce@spearce.org>2010-11-09 14:36:01 -0800
commit6af7e4d91ab3f4199dc82252e330039854716517 (patch)
treec8ffac62c93c5eb5ee43dfd22d5cce7e3d02fd3d
parentb087bba3bd6c8f39ff35264703c316569fafe2ab (diff)
downloadjgit-6af7e4d91ab3f4199dc82252e330039854716517.tar.gz
jgit-6af7e4d91ab3f4199dc82252e330039854716517.zip
Fix URIish parsing of absolute scp-style URIs
We stopped handling URIs such as "example.com:/some/p ath", because this was confused with the Windows absolute path syntax of "c:/path". Support absolute style scp URIs again, but only when the host name is more than 2 characters long. Change-Id: I9ab049bc9aad2d8d42a78c7ab34fa317a28efc1a Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java14
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java32
2 files changed, 38 insertions, 8 deletions
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 fe8e38fc7e..93d909d7db 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
@@ -172,7 +172,7 @@ public class URIishTest extends TestCase {
assertEquals(u, new URIish(str));
}
- public void testScpStyleWithoutUser() throws Exception {
+ public void testScpStyleWithoutUserRelativePath() throws Exception {
final String str = "example.com:some/p ath";
URIish u = new URIish(str);
assertNull(u.getScheme());
@@ -184,6 +184,18 @@ public class URIishTest extends TestCase {
assertEquals(u, new URIish(str));
}
+ public void testScpStyleWithoutUserAbsolutePath() throws Exception {
+ final String str = "example.com:/some/p ath";
+ URIish u = new URIish(str);
+ assertNull(u.getScheme());
+ assertTrue(u.isRemote());
+ assertEquals("/some/p ath", u.getPath());
+ assertEquals("example.com", u.getHost());
+ assertEquals(-1, u.getPort());
+ assertEquals(str, u.toString());
+ assertEquals(u, new URIish(str));
+ }
+
public void testScpStyleWithUser() throws Exception {
final String str = "user@example.com:some/p ath";
URIish u = new URIish(str);
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 94f4a67d58..bc24516a65 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java
@@ -155,7 +155,7 @@ public class URIish implements Serializable {
/**
* A pattern matching a SCP URI's of the form user@host:path/to/repo.git
*/
- private static final Pattern SCP_URI = Pattern.compile("^" //
+ private static final Pattern RELATIVE_SCP_URI = Pattern.compile("^" //
+ OPT_USER_PWD_P //
+ HOST_P //
+ ":(" //
@@ -163,6 +163,16 @@ public class URIish implements Serializable {
+ RELATIVE_PATH_P //
+ ")$");
+ /**
+ * A pattern matching a SCP URI's of the form user@host:/path/to/repo.git
+ */
+ private static final Pattern ABSOLUTE_SCP_URI = Pattern.compile("^" //
+ + OPT_USER_PWD_P //
+ + "([^/:]{2,})" //
+ + ":(" //
+ + "/" + RELATIVE_PATH_P //
+ + ")$");
+
private String scheme;
private String path;
@@ -200,19 +210,27 @@ public class URIish implements Serializable {
n2e(matcher.group(6)) + n2e(matcher.group(7)),
scheme);
} else {
- matcher = SCP_URI.matcher(s);
+ matcher = RELATIVE_SCP_URI.matcher(s);
if (matcher.matches()) {
user = matcher.group(1);
pass = matcher.group(2);
host = matcher.group(3);
path = matcher.group(4);
} else {
- matcher = LOCAL_FILE.matcher(s);
+ matcher = ABSOLUTE_SCP_URI.matcher(s);
if (matcher.matches()) {
- path = matcher.group(1);
- } else
- throw new URISyntaxException(s,
- JGitText.get().cannotParseGitURIish);
+ user = matcher.group(1);
+ pass = matcher.group(2);
+ host = matcher.group(3);
+ path = matcher.group(4);
+ } else {
+ matcher = LOCAL_FILE.matcher(s);
+ if (matcher.matches()) {
+ path = matcher.group(1);
+ } else
+ throw new URISyntaxException(s,
+ JGitText.get().cannotParseGitURIish);
+ }
}
}
}