Properly preserve port and username from parsed HTTP URLs.
authorJelmer Vernooij <jelmer@jelmer.uk>
Wed, 14 Nov 2018 02:05:25 +0000 (02:05 +0000)
committerJelmer Vernooij <jelmer@jelmer.uk>
Wed, 14 Nov 2018 02:05:25 +0000 (02:05 +0000)
NEWS
dulwich/client.py
dulwich/tests/test_client.py

diff --git a/NEWS b/NEWS
index bca6f574eaca321700bc7d3e3cea3e00522e412c..b4faf679cdcecf05d4411a1593e64777d9b6c652 100644 (file)
--- a/NEWS
+++ b/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
index ed1a2d96a82b8f4733f25b35c467c06909a8c1b8..66428ac2f8f4726ddf1cd0bf90897a177b3ff6de 100644 (file)
@@ -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):
index e9fa573be750eb92fb69809d88be50468e78ae8a..5ea6b480f802a4fd1d99f3efaac72a4ac1f66891 100644 (file)
@@ -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):