Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
gh-67693: Fix urlunparse() and urlunsplit() for URIs with path starting with multiple slashes and no authority#113563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ff16c46151e39c0e177fdeea029dcc9067bfb03e5f26951a77f495b0f5ab0c162957feFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -103,15 +103,17 @@ | ||
| class UrlParseTestCase(unittest.TestCase): | ||
| def checkRoundtrips(self, url, parsed, split): | ||
| def checkRoundtrips(self, url, parsed, split, url2=None): | ||
| if url2 is None: | ||
| url2 = url | ||
| result = urllib.parse.urlparse(url) | ||
| self.assertSequenceEqual(result, parsed) | ||
| t = (result.scheme, result.netloc, result.path, | ||
| result.params, result.query, result.fragment) | ||
| self.assertSequenceEqual(t, parsed) | ||
| # put it back together and it should be the same | ||
| result2 = urllib.parse.urlunparse(result) | ||
| self.assertSequenceEqual(result2, url) | ||
| self.assertSequenceEqual(result2, url2) | ||
| self.assertSequenceEqual(result2, result.geturl()) | ||
| # the result of geturl() is a fixpoint; we can always parse it | ||
| @@ -137,7 +139,7 @@ def checkRoundtrips(self, url, parsed, split): | ||
| result.query, result.fragment) | ||
| self.assertSequenceEqual(t, split) | ||
| result2 = urllib.parse.urlunsplit(result) | ||
| self.assertSequenceEqual(result2, url) | ||
| self.assertSequenceEqual(result2, url2) | ||
| self.assertSequenceEqual(result2, result.geturl()) | ||
| # check the fixpoint property of re-parsing the result of geturl() | ||
| @@ -175,9 +177,39 @@ def test_qs(self): | ||
| def test_roundtrips(self): | ||
| str_cases = [ | ||
| ('path/to/file', | ||
| ('', '', 'path/to/file', '', '', ''), | ||
| ('', '', 'path/to/file', '', '')), | ||
| ('/path/to/file', | ||
| ('', '', '/path/to/file', '', '', ''), | ||
| ('', '', '/path/to/file', '', '')), | ||
| ('//path/to/file', | ||
| ('', 'path', '/to/file', '', '', ''), | ||
| ('', 'path', '/to/file', '', '')), | ||
| ('////path/to/file', | ||
| ('', '', '//path/to/file', '', '', ''), | ||
| ('', '', '//path/to/file', '', '')), | ||
| ('scheme:path/to/file', | ||
| ('scheme', '', 'path/to/file', '', '', ''), | ||
| ('scheme', '', 'path/to/file', '', '')), | ||
| ('scheme:/path/to/file', | ||
| ('scheme', '', '/path/to/file', '', '', ''), | ||
| ('scheme', '', '/path/to/file', '', '')), | ||
| ('scheme://path/to/file', | ||
| ('scheme', 'path', '/to/file', '', '', ''), | ||
| ('scheme', 'path', '/to/file', '', '')), | ||
| ('scheme:////path/to/file', | ||
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This case was broken. | ||
| ('scheme', '', '//path/to/file', '', '', ''), | ||
| ('scheme', '', '//path/to/file', '', '')), | ||
| ('file:///tmp/junk.txt', | ||
| ('file', '', '/tmp/junk.txt', '', '', ''), | ||
| ('file', '', '/tmp/junk.txt', '', '')), | ||
| ('file:////tmp/junk.txt', | ||
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This case was broken. | ||
| ('file', '', '//tmp/junk.txt', '', '', ''), | ||
| ('file', '', '//tmp/junk.txt', '', '')), | ||
| ('file://///tmp/junk.txt', | ||
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This case was broken. | ||
| ('file', '', '///tmp/junk.txt', '', '', ''), | ||
| ('file', '', '///tmp/junk.txt', '', '')), | ||
| ('imap://mail.python.org/mbox1', | ||
| ('imap', 'mail.python.org', '/mbox1', '', '', ''), | ||
| ('imap', 'mail.python.org', '/mbox1', '', '')), | ||
| @@ -213,6 +245,38 @@ def _encode(t): | ||
| for url, parsed, split in str_cases + bytes_cases: | ||
| self.checkRoundtrips(url, parsed, split) | ||
| def test_roundtrips_normalization(self): | ||
| str_cases = [ | ||
| ('///path/to/file', | ||
| '/path/to/file', | ||
| ('', '', '/path/to/file', '', '', ''), | ||
| ('', '', '/path/to/file', '', '')), | ||
| ('scheme:///path/to/file', | ||
| 'scheme:/path/to/file', | ||
| ('scheme', '', '/path/to/file', '', '', ''), | ||
| ('scheme', '', '/path/to/file', '', '')), | ||
| ('file:/tmp/junk.txt', | ||
| 'file:///tmp/junk.txt', | ||
| ('file', '', '/tmp/junk.txt', '', '', ''), | ||
| ('file', '', '/tmp/junk.txt', '', '')), | ||
| ('http:/tmp/junk.txt', | ||
| 'http:///tmp/junk.txt', | ||
| ('http', '', '/tmp/junk.txt', '', '', ''), | ||
| ('http', '', '/tmp/junk.txt', '', '')), | ||
| ('https:/tmp/junk.txt', | ||
| 'https:///tmp/junk.txt', | ||
| ('https', '', '/tmp/junk.txt', '', '', ''), | ||
| ('https', '', '/tmp/junk.txt', '', '')), | ||
| ] | ||
| def _encode(t): | ||
| return (t[0].encode('ascii'), | ||
| t[1].encode('ascii'), | ||
| tuple(x.encode('ascii') for x in t[2]), | ||
| tuple(x.encode('ascii') for x in t[3])) | ||
| bytes_cases = [_encode(x) for x in str_cases] | ||
| for url, url2, parsed, split in str_cases + bytes_cases: | ||
| self.checkRoundtrips(url, parsed, split, url2) | ||
| def test_http_roundtrips(self): | ||
| # urllib.parse.urlsplit treats 'http:' as an optimized special case, | ||
| # so we test both 'http:' and 'https:' in all the following. | ||
serhiy-storchaka marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Fix :func:`urllib.parse.urlunparse` and :func:`urllib.parse.urlunsplit` for URIs with path starting with multiple slashes and no authority. | ||
| Based on patch by Ashwin Ramaswami. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case was broken.