-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Use rfc3986.validator.Validator for parse_url #1531
Merged
Merged
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5135adf
Use the validator for parse_url
sethmlarson 40b6e20
Add more URLs
sethmlarson 637bd13
Use rfc3986.URIReference instead of ParseResult
sethmlarson a05d157
Update rfc3986 to master
sethmlarson 821c108
Update parse_url to require components too
sethmlarson 134367e
Split path test cases
sethmlarson 65f6cb2
temp commit
sethmlarson cc82882
Add unit tests for international hosts
sethmlarson 323eb56
use re
sethmlarson 7866572
Add all international components
sethmlarson 0ef8b81
fix flake
sethmlarson 1e6681e
Merge branch 'master' of https://github.com/urllib3/urllib3 into url-…
sethmlarson 357d701
Upgrade rfc3986 to v1.3.0
sethmlarson 0b1727e
Update parse_url and tests
sethmlarson c2367d8
Merge
sethmlarson 15be9ca
Fix lint issues in tests
sethmlarson File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,6 +148,7 @@ def test_invalid_url(self, url): | |
'http://JeremyCline:Hunter2@example.com:8080/'), | ||
('HTTPS://Example.Com/?Key=Value', 'https://example.com/?Key=Value'), | ||
('Https://Example.Com/#Fragment', 'https://example.com/#Fragment'), | ||
('[::Ff%etH0%Ff]/%ab%Af', '[::ff%25etH0%Ff]/%AB%AF'), | ||
]) | ||
def test_parse_url_normalization(self, url, expected_normalized_url): | ||
"""Assert parse_url normalizes the scheme/host, and only the scheme/host""" | ||
|
@@ -166,7 +167,7 @@ def test_parse_url_normalization(self, url, expected_normalized_url): | |
# Path/query/fragment | ||
('', Url()), | ||
('/', Url(path='/')), | ||
('/abc/../def', Url(path="/abc/../def")), | ||
('/abc/../def', Url(path="/def")), | ||
('#?/!google.com/?foo', Url(path='', fragment='?/!google.com/?foo')), | ||
('/foo', Url(path='/foo')), | ||
('/foo?bar=baz', Url(path='/foo', query='bar=baz')), | ||
|
@@ -220,6 +221,10 @@ def test_parse_url(self, url, expected_url): | |
|
||
@pytest.mark.parametrize('url, expected_url', parse_url_host_map) | ||
def test_unparse_url(self, url, expected_url): | ||
|
||
if '/../' in url: | ||
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 is odd 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. I agree, maybe I can split it out into a different test case about path normalization / unsplitting. |
||
url = url.replace('/abc/../', '/') | ||
|
||
assert url == expected_url.url | ||
|
||
def test_parse_url_invalid_IPv6(self): | ||
|
@@ -271,12 +276,12 @@ def test_netloc(self, url, expected_netloc): | |
|
||
# CVE-2016-5699 | ||
("http://127.0.0.1%0d%0aConnection%3a%20keep-alive", | ||
Url("http", host="127.0.0.1%0d%0aConnection%3a%20keep-alive")), | ||
Url("http", host="127.0.0.1%0d%0aconnection%3a%20keep-alive")), | ||
|
||
# NodeJS unicode -> double dot | ||
(u"http://google.com/\uff2e\uff2e/abc", Url("http", | ||
host="google.com", | ||
path='/%ef%bc%ae%ef%bc%ae/abc')), | ||
path='/%EF%BC%AE%EF%BC%AE/abc')), | ||
|
||
# Scheme without :// | ||
("javascript:a='@google.com:12345/';alert(0)", Url(scheme="javascript", | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
So you want to validate literally everything, yes? I wonder if we could make a better API for this.
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.
Yeah validate all components. Leaving the hard work to you I can whip up a patch, tests, and docs if you can think of a name for the interface. ;)
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.
validate_all_the_components_<emoji>