changeset 392:35993ba9d119

urls: Make sure we preserve username in urls given to ssh.
author Augie Fackler <durin42@gmail.com>
date Sat, 06 Jun 2009 11:53:21 -0500
parents dbdcb97b38af
children e857e5cfc10f
files hgsubversion/svnwrap/svn_swig_wrapper.py tests/test_urls.py
diffstat 2 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/svnwrap/svn_swig_wrapper.py
+++ b/hgsubversion/svnwrap/svn_swig_wrapper.py
@@ -115,6 +115,7 @@ def _create_auth_baton(pool):
 
     return core.svn_auth_open(providers, pool)
 
+
 def parse_url(url):
     """Parse a URL and return a tuple (username, password, url)
     """
@@ -124,12 +125,17 @@ def parse_url(url):
         userpass, netloc = netloc.split('@')
         if ':' in userpass:
             user, passwd = userpass.split(':')
-            user, passwd = urllib.unquote(user) or None, urllib.unquote(passwd) or None
+            user, passwd = (urllib.unquote(user) or None,
+                            urllib.unquote(passwd) or None,
+                            )
         else:
             user = urllib.unquote(userpass) or None
+        if user and scheme == 'svn+ssh':
+            netloc = '@'.join((user, netloc, ))
     url = urlparse.urlunparse((scheme, netloc, path, params, query, fragment))
     return (user, passwd, url)
 
+
 class Revision(tuple):
     """Wrapper for a Subversion revision.
 
--- a/tests/test_urls.py
+++ b/tests/test_urls.py
@@ -15,6 +15,14 @@ class TestSubversionUrls(test_util.TestB
         self.assertEqual((None, 't3stpw', 'svn+ssh://svn.testurl.com/repo'),
                          parse_url('svn+ssh://:t3stpw@svn.testurl.com/repo'))
 
+    def test_svnssh_preserve_user(self):
+        self.assertEqual(
+            ('user', 't3stpw', 'svn+ssh://user@svn.testurl.com/repo', ),
+            parse_url('svn+ssh://user:t3stpw@svn.testurl.com/repo'))
+        self.assertEqual(
+            ('user2', None, 'svn+ssh://user2@svn.testurl.com/repo', ),
+            parse_url('svn+ssh://user2@svn.testurl.com/repo'))
+
     def test_user_password_url(self):
         self.assertEqual(('joe', 't3stpw', 'https://svn.testurl.com/repo'),
                          parse_url('https://joe:t3stpw@svn.testurl.com/repo'))