From afd4f3b0cf7aefa2e5988db1d81cb2c0f10efe10 Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Fri, 4 Nov 2011 17:53:44 +0100 Subject: [PATCH] Allow '\' in user names in URI-ish Actually this is not ok according to the RFC, but this implementation is ment to be Git compatible. A '\' is needed when the authentication requires or allows authentication to a Windows domain where the user name can be specified as DOMAIN\user. Change-Id: If02f258c032486f1afd2e09592a3c7069942eb8b --- .../eclipse/jgit/transport/URIishTest.java | 66 +++++++++++++++++++ .../org/eclipse/jgit/transport/URIish.java | 2 +- 2 files changed, 67 insertions(+), 1 deletion(-) 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 9b4ebf90d..d797dd435 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 @@ -320,6 +320,22 @@ public class URIishTest { assertEquals(u, new URIish(str)); } + @Test + public void testSshProtoWithADUserPassAndPort() throws Exception { + final String str = "ssh://DOMAIN\\user:pass@example.com:33/some/p ath"; + URIish u = new URIish(str); + assertEquals("ssh", u.getScheme()); + assertTrue(u.isRemote()); + assertEquals("/some/p ath", u.getPath()); + assertEquals("example.com", u.getHost()); + assertEquals("DOMAIN\\user", u.getUser()); + assertEquals("pass", u.getPass()); + assertEquals(33, u.getPort()); + assertEquals(str, u.toPrivateString()); + assertEquals(u.setPass(null).toPrivateString(), u.toString()); + assertEquals(u, new URIish(str)); + } + @Test public void testGitWithUserHome() throws Exception { final String str = "git://example.com/~some/p ath"; @@ -582,4 +598,54 @@ public class URIishTest { URIish u = new URIish(incorrectSshUrl); assertFalse(TransportGitSsh.PROTO_SSH.canHandle(u)); } + + @Test + public void testALot() throws URISyntaxException { + // user pass host port path + // 1 2 3 4 5 + String[][] tests = { + new String[] { "%1$s://%2$s:%3$s@%4$s:%5$s/%6$s", "%1$s", + "%2$s", "%3$s", "%4$s", "%5$s", "%6$s" }, + new String[] { "%1$s://%2$s@%4$s:%5$s/%6$s", "%1$s", "%2$s", + null, "%4$s", "%5$s", "%6$s" }, + new String[] { "%1$s://%2$s@%4$s/%6$s", "%1$s", "%2$s", null, + "%4$s", null, "%6$s" }, + new String[] { "%1$s://%4$s/%6$s", "%1$s", null, null, "%4$s", + null, "%6$s" }, }; + String[] schemes = new String[] { "ssh", "ssh+git", "http", "https" }; + String[] users = new String[] { "me", "l usr\\example.com", + "lusr\\example" }; + String[] passes = new String[] { "wtf", }; + String[] hosts = new String[] { "example.com", "1.2.3.4" }; + String[] ports = new String[] { "1234", "80" }; + String[] paths = new String[] { "/", "/abc", "D:/x", "D:\\x" }; + for (String[] test : tests) { + String fmt = test[0]; + for (String scheme : schemes) { + for (String user : users) { + for (String pass : passes) { + for (String host : hosts) { + for (String port : ports) { + for (String path : paths) { + String url = String.format(fmt, scheme, + user, pass, host, port, path); + String[] expect = new String[test.length]; + for (int i = 1; i < expect.length; ++i) + if (test[i] != null) + expect[i] = String.format(test[i], + scheme, user, pass, host, + port, path); + URIish urIish = new URIish(url); + assertEquals(url, expect[1], + urIish.getScheme()); + assertEquals(url, expect[2], + urIish.getUser()); + } + } + } + } + } + } + } + } } 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 8534724cb..8254c1f20 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java @@ -77,7 +77,7 @@ public class URIish implements Serializable { * capturing groups: the first containing the user and the second containing * the password */ - private static final String OPT_USER_PWD_P = "(?:([^\\\\/:@]+)(?::([^\\\\/]+))?@)?"; + private static final String OPT_USER_PWD_P = "(?:([^/:@]+)(?::([^\\\\/]+))?@)?"; /** * Part of a pattern which matches the host part of URIs. Defines one