-
Notifications
You must be signed in to change notification settings - Fork 570
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The URI to IRI conversion was percentage-quoting characters that should not have been quoted, like equals in the query string. It was also not quoting things that should have been quoted, like the username and password components of a URI. This change improves the conversion by only quoting characters that are not allowed in specific parts of the URI and quoting previously unquoted components. The safe characters for each segment are taken from [RFC3986](https://datatracker.ietf.org/doc/html/rfc3986). The new behavior is heavily inspired by [`werkzeug.urls.iri_to_uri`](https://github.com/pallets/werkzeug/blob/92c6380248c7272ee668e1f8bbd80447027ccce2/src/werkzeug/urls.py#L926-L931) though there are some differences. - Closes <#2120>.
- Loading branch information
Showing
5 changed files
with
169 additions
and
19 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -635,6 +635,24 @@ def test_get_tree( | |
"http://example.com:1231/", | ||
}, | ||
), | ||
( | ||
"http://example.com:1231/a=b", | ||
{ | ||
"http://example.com:1231/a=b", | ||
}, | ||
), | ||
( | ||
"http://aé:aé@example.com:1231/bé/a=bé&c=d#a=bé&c=d", | ||
{ | ||
"http://a%C3%A9:a%C3%[email protected]:1231/b%C3%A9/a=b%C3%A9&c=d#a=b%C3%A9&c=d", | ||
}, | ||
), | ||
( | ||
"http://a%C3%A9:a%C3%[email protected]:1231/b%C3%A9/a=b%C3%A9&c=d#a=b%C3%A9&c=d", | ||
{ | ||
"http://a%C3%A9:a%C3%[email protected]:1231/b%C3%A9/a=b%C3%A9&c=d#a=b%C3%A9&c=d", | ||
}, | ||
), | ||
], | ||
) | ||
def test_iri2uri(iri: str, expected_result: Union[Set[str], Type[Exception]]) -> None: | ||
|
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from typing import Any | ||
from urllib.parse import ParseResult | ||
|
||
|
||
class EqWildcard: | ||
""" | ||
An object that matches anything. | ||
""" | ||
|
||
def __eq__(self, other: Any) -> Any: | ||
return True | ||
|
||
def __req__(self, other: Any) -> Any: | ||
return True | ||
|
||
def __repr__(self) -> str: | ||
return "EqWildcard()" | ||
|
||
|
||
EQ_WILDCARD: Any = EqWildcard() | ||
|
||
|
||
URL_PARSE_RESULT_WILDCARD = ParseResult( | ||
EQ_WILDCARD, EQ_WILDCARD, EQ_WILDCARD, EQ_WILDCARD, EQ_WILDCARD, EQ_WILDCARD | ||
) | ||
""" | ||
This should be equal to any `ParseResult` object. | ||
""" |