Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/project/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ Improvements
Bug fixes
.........

* Preserved percent-encoded sequences in paths and queries when connecting to
internationalized URIs.

* Fixed a regression from 16.1 where the legacy implementation rejected
non-ASCII headers.

Expand Down
4 changes: 2 additions & 2 deletions src/websockets/uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ def parse_uri(uri: str) -> WebSocketURI:
# Input contains non-ASCII characters.
# It must be an IRI. Convert it to a URI.
host = host.encode("idna").decode()
path = urllib.parse.quote(path, safe=DELIMS)
query = urllib.parse.quote(query, safe=DELIMS)
path = urllib.parse.quote(path, safe=DELIMS + "%")
query = urllib.parse.quote(query, safe=DELIMS + "%")
if username is not None:
assert password is not None
username = urllib.parse.quote(username, safe=DELIMS)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
("ws://localhost", "/"),
("ws://localhost/path?query", "/path?query"),
("ws://høst/πass?qùéry", "/%CF%80ass?q%C3%B9%C3%A9ry"),
("ws://høst/a%20b?x=%26%3D%2B", "/a%20b?x=%26%3D%2B"),
("ws://localhost/café%2Fmenu?x=%25", "/caf%C3%A9%2Fmenu?x=%25"),
("ws://localhost/a%2fb?q=café%26tea", "/a%2fb?q=caf%C3%A9%26tea"),
]

URIS_WITH_USER_INFO = [
Expand Down