-
Notifications
You must be signed in to change notification settings - Fork 41
Unicode mixed percent decoding #59
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -510,10 +510,11 @@ def _percent_decode(text, normalize_case=False, subencoding='utf-8', | |
| """Convert percent-encoded text characters to their normal, | ||
| human-readable equivalents. | ||
|
|
||
| All characters in the input text must be valid ASCII. All special | ||
| characters underlying the values in the percent-encoding must be | ||
| valid UTF-8. If a non-UTF8-valid string is passed, the original | ||
| text is returned with no changes applied. | ||
| All characters in the input text must be encodable by | ||
| *subencoding*. All special characters underlying the values in the | ||
| percent-encoding must be decodable as *subencoding*. If a | ||
| non-*subencoding*-valid string is passed, the original text is | ||
| returned with no changes applied. | ||
|
|
||
| Only called by field-tailored variants, e.g., | ||
| :func:`_decode_path_part`, as every percent-encodable part of the | ||
|
|
@@ -523,18 +524,22 @@ def _percent_decode(text, normalize_case=False, subencoding='utf-8', | |
| u'abc def' | ||
|
|
||
| Args: | ||
| text (unicode): The ASCII text with percent-encoding present. | ||
| text (unicode): Text with percent-encoding present. | ||
| normalize_case (bool): Whether undecoded percent segments, such | ||
| as encoded delimiters, should be uppercased, per RFC 3986 | ||
| Section 2.1. See :func:`_decode_path_part` for an example. | ||
| subencoding (unicode): The name of the encoding underlying the | ||
|
Member
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.
|
||
| percent-encoding. Pass `False` to get back raw bytes. | ||
| raise_subencoding_exc (bool): Whether an error in decoding the bytes | ||
| underlying the percent-decoding should be raised. | ||
|
|
||
| Returns: | ||
| unicode: The percent-decoded version of *text*, with UTF-8 | ||
| decoding applied. | ||
| unicode: The percent-decoded version of *text*, decoded by | ||
| *subencoding*, unless `subencoding=False` which returns bytes. | ||
|
|
||
| """ | ||
| try: | ||
| quoted_bytes = text.encode("ascii") | ||
| quoted_bytes = text.encode('utf-8' if subencoding is False else subencoding) | ||
| except UnicodeEncodeError: | ||
| return text | ||
|
|
||
|
|
@@ -1673,8 +1678,7 @@ def path(self): | |
| return self._path | ||
| except AttributeError: | ||
| pass | ||
| self._path = tuple([_percent_decode(_encode_path_part(p), | ||
| raise_subencoding_exc=True) | ||
| self._path = tuple([_percent_decode(p, raise_subencoding_exc=True) | ||
| for p in self._url.path]) | ||
| return self._path | ||
|
|
||
|
|
@@ -1684,8 +1688,7 @@ def query(self): | |
| return self._query | ||
| except AttributeError: | ||
| pass | ||
| _q = [tuple(_percent_decode(_encode_query_part(x), | ||
| raise_subencoding_exc=True) | ||
| _q = [tuple(_percent_decode(x, raise_subencoding_exc=True) | ||
| if x is not None else None | ||
| for x in (k, v)) | ||
| for k, v in self._url.query] | ||
|
|
@@ -1699,8 +1702,7 @@ def fragment(self): | |
| except AttributeError: | ||
| pass | ||
| frag = self._url.fragment | ||
| self._fragment = _percent_decode(_encode_fragment_part(frag), | ||
| raise_subencoding_exc=True) | ||
| self._fragment = _percent_decode(frag, raise_subencoding_exc=True) | ||
| return self._fragment | ||
|
|
||
| @property | ||
|
|
@@ -1709,8 +1711,7 @@ def userinfo(self): | |
| return self._userinfo | ||
| except AttributeError: | ||
| pass | ||
| self._userinfo = tuple([_percent_decode(_encode_userinfo_part(p), | ||
| raise_subencoding_exc=True) | ||
| self._userinfo = tuple([_percent_decode(p, raise_subencoding_exc=True) | ||
| for p in self._url.userinfo.split(':', 1)]) | ||
| return self._userinfo | ||
|
|
||
|
|
||
This file contains hidden or 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
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.
An earlier part of the docstring contradicts this. Please rewrite it to document the new API.