Browse Source

Fix handling of unknown URL schemes in get_transport_and_path. (#465).

Jelmer Vernooij 8 years ago
parent
commit
d75a1de49a
3 changed files with 27 additions and 4 deletions
  1. 3 0
      NEWS
  2. 8 4
      dulwich/client.py
  3. 16 0
      dulwich/tests/test_client.py

+ 3 - 0
NEWS

@@ -27,6 +27,9 @@
     consistent with the documentation for that method.
     (#461, Jelmer Vernooij)
 
+  * Fix handling of unknown URL schemes in get_transport_and_path.
+    (#465, Jelmer Vernooij)
+
 0.15.0	2016-10-09
 
  BUG FIXES

+ 8 - 4
dulwich/client.py

@@ -1273,12 +1273,16 @@ def get_transport_and_path(location, **kwargs):
 
     if ':' in location and not '@' in location:
         # SSH with no user@, zero or one leading slash.
-        (hostname, path) = location.split(':')
+        (hostname, path) = location.split(':', 1)
         return SSHGitClient(hostname, **kwargs), path
-    elif '@' in location and ':' in location:
+    elif ':' in location:
         # SSH with user@host:foo.
-        user_host, path = location.split(':')
-        user, host = user_host.rsplit('@')
+        user_host, path = location.split(':', 1)
+        if '@' in user_host:
+            user, host = user_host.rsplit('@', 1)
+        else:
+            user = None
+            host = user_host
         return SSHGitClient(host, username=user, **kwargs), path
 
     # Otherwise, assume it's a local path.

+ 16 - 0
dulwich/tests/test_client.py

@@ -380,6 +380,22 @@ class TestGetTransportAndPath(TestCase):
         self.assertEqual(1234, c.port)
         self.assertEqual('bar/baz', path)
 
+    def test_username_and_port_explicit_unknown_scheme(self):
+        c, path = get_transport_and_path(
+            'unknown://git@server:7999/dply/stuff.git')
+        self.assertTrue(isinstance(c, SSHGitClient))
+        self.assertEqual('unknown', c.host)
+        self.assertEqual('//git@server:7999/dply/stuff.git', path)
+
+    def test_username_and_port_explicit(self):
+        c, path = get_transport_and_path(
+            'ssh://git@server:7999/dply/stuff.git')
+        self.assertTrue(isinstance(c, SSHGitClient))
+        self.assertEqual('git', c.username)
+        self.assertEqual('server', c.host)
+        self.assertEqual(7999, c.port)
+        self.assertEqual('dply/stuff.git', path)
+
     def test_ssh_abspath_explicit(self):
         c, path = get_transport_and_path('git+ssh://foo.com//bar/baz')
         self.assertTrue(isinstance(c, SSHGitClient))