Fix intersphinx fails if mapping URL contains any port

This commit is contained in:
Takeshi KOMIYA
2016-04-25 11:08:03 +09:00
parent ad738a0978
commit d38915e2a5
3 changed files with 15 additions and 1 deletions

View File

@@ -35,6 +35,7 @@ Bugs fixed
* Sphinx crashes if self referenced toctree found
* #2481: spelling mistake for mecab search splitter. Thanks to Naoki Sato.
* #2309: Fix could not refer "indirect hyperlink targets" by ref-role
* intersphinx fails if mapping URL contains any port
Release 1.4.1 (released Apr 12, 2016)

View File

@@ -150,7 +150,10 @@ def _strip_basic_auth(url):
password = url_parts.password
frags = list(url_parts)
# swap out "user[:pass]@hostname" for "hostname"
frags[1] = url_parts.hostname
if url_parts.port:
frags[1] = "%s:%s" % (url_parts.hostname, url_parts.port)
else:
frags[1] = url_parts.hostname
url = parse.urlunsplit(frags)
return (url, username, password)

View File

@@ -199,6 +199,16 @@ class TestStripBasicAuth(unittest.TestCase):
self.assertEqual(None, actual_username)
self.assertEqual(None, actual_password)
def test_having_port(self):
"""basic auth creds correctly stripped from URL containing creds even if URL
contains port"""
url = 'https://user:12345@domain.com:8080/project/objects.inv'
expected = 'https://domain.com:8080/project/objects.inv'
actual_url, actual_username, actual_password = _strip_basic_auth(url)
self.assertEqual(expected, actual_url)
self.assertEqual('user', actual_username)
self.assertEqual('12345', actual_password)
@mock.patch('six.moves.urllib.request.HTTPBasicAuthHandler')
@mock.patch('six.moves.urllib.request.HTTPPasswordMgrWithDefaultRealm')