Browse Source

Properly preserve port and username from parsed HTTP URLs.

Jelmer Vernooij 6 years ago
parent
commit
1ee03256ad
3 changed files with 17 additions and 2 deletions
  1. 3 0
      NEWS
  2. 6 2
      dulwich/client.py
  3. 8 0
      dulwich/tests/test_client.py

+ 3 - 0
NEWS

@@ -3,6 +3,9 @@
  * Fix encoding when reading README file in setup.py.
    (egor <egor@sourced.tech>, #668)
 
+ * Preserve port and username in parsed HTTP URLs.
+   (Jelmer Vernooij)
+
 0.19.7	2018-11-05
 
  CHANGES

+ 6 - 2
dulwich/client.py

@@ -1455,8 +1455,12 @@ class HttpGitClient(GitClient):
         username = parsedurl.username
         if username is not None:
             kwargs['username'] = urlunquote(username)
-        # TODO(jelmer): This also strips the username
-        parsedurl = parsedurl._replace(netloc=parsedurl.hostname)
+        netloc = parsedurl.hostname
+        if parsedurl.port:
+            netloc = "%s:%s" % (netloc, parsedurl.port)
+        if parsedurl.username:
+            netloc = "%s@%s" % (parsedurl.username, netloc)
+        parsedurl = parsedurl._replace(netloc=netloc)
         return cls(urlparse.urlunparse(parsedurl), **kwargs)
 
     def __repr__(self):

+ 8 - 0
dulwich/tests/test_client.py

@@ -673,6 +673,14 @@ class TestGetTransportAndPathFromUrl(TestCase):
         url = 'https://github.com/jelmer/dulwich'
         c, path = get_transport_and_path_from_url(url)
         self.assertTrue(isinstance(c, HttpGitClient))
+        self.assertEqual('https://github.com', c.get_url(b'/'))
+        self.assertEqual('/jelmer/dulwich', path)
+
+    def test_http_port(self):
+        url = 'https://github.com:9090/jelmer/dulwich'
+        c, path = get_transport_and_path_from_url(url)
+        self.assertEqual('https://github.com:9090', c.get_url(b'/'))
+        self.assertTrue(isinstance(c, HttpGitClient))
         self.assertEqual('/jelmer/dulwich', path)
 
     def test_file(self):