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
Change URI verification in command line tools #4603
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -133,3 +133,15 @@ def strip_url(url, strip_credentials=True, strip_default_port=True, origin_only= | |||||||
'' if origin_only else parsed_url.query, | ||||||||
'' if strip_fragment else parsed_url.fragment | ||||||||
)) | ||||||||
|
||||||||
|
||||||||
def is_uri(text, protocols={'http', 'https', 'file'}): | ||||||||
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. 💄 It may be better to make
Suggested change
Also, maybe it should be |
||||||||
regex = r'^(([a-zA-Z][-+.\w]*):)(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?' | ||||||||
pattern = re.compile(regex) | ||||||||
match = pattern.fullmatch(text) | ||||||||
Comment on lines
+140
to
+141
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 would be simpler and the performance should be the same:
Suggested change
|
||||||||
if match is None: | ||||||||
return False | ||||||||
scheme = match.group(2).lower() | ||||||||
if protocols is not None and scheme not in protocols: | ||||||||
return False | ||||||||
return True |
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.
See
settings.getwithbase
. Using that, extracting this code into a function is less important, as you could simplify the line below as: