Skip to content
Myr

Allow URLs where username or password contains unescaped '@'. (#2986)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Add test cases for userinfo in URL * Resolve failing test cases * Update CHANGELOG.md * Update CHANGELOG.md

authored by Tom Christie · committed by GitHub · parent 5b5f6d8 · Browse files · 3 files+56 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+56 added−2 removed

  • tests:+48 added−0 removed
  • other:+8 added−2 removed

3 files+56 added−2 removed

modified:httpx/_urlparse.py+2 added-2 removed
60 unmodified lines
61AUTHORITY_REGEX = re.compile(62 (63 r"(?:(?P<userinfo>{userinfo})@)?" r"(?P<host>{host})" r":?(?P<port>{port})?"64 ).format(65 userinfo="[^@]*", # Any character sequence not including '@'.66 host="(\\[.*\\]|[^:]*)", # Either any character sequence not including ':',65 userinfo=".*", # Any character sequence.66 host="(\\[.*\\]|[^:@]*)", # Either any character sequence excluding ':' or '@',67 # or an IPv6 address enclosed within square brackets.68 port=".*", # Any character sequence.69 )70)
397 unmodified lines
modified:tests/models/test_url.py+48 added
130 unmodified lines
131 assert str(url) == "https://example.org:123/path/to/somewhere?a=123"132 assert url.params == httpx.QueryParams({"a": "123"})133134135# Tests for username and password136137138@pytest.mark.parametrize(139 "url,userinfo,username,password",140 [141 # username and password in URL.142 (143 "https://username:password@example.com",144 b"username:password",145 "username",146 "password",147 ),148 # username and password in URL with percent escape sequences.149 (150 "https://username%40gmail.com:pa%20ssword@example.com",151 b"username%40gmail.com:pa%20ssword",152 "username@gmail.com",153 "pa ssword",154 ),155 (156 "https://user%20name:p%40ssword@example.com",157 b"user%20name:p%40ssword",158 "user name",159 "p@ssword",160 ),161 # username and password in URL without percent escape sequences.162 (163 "https://username@gmail.com:pa ssword@example.com",164 b"username%40gmail.com:pa%20ssword",165 "username@gmail.com",166 "pa ssword",167 ),168 (169 "https://user name:p@ssword@example.com",170 b"user%20name:p%40ssword",171 "user name",172 "p@ssword",173 ),174 ],175)176def test_url_username_and_password(url, userinfo, username, password):177 url = httpx.URL(url)178 assert url.userinfo == userinfo179 assert url.username == username180 assert url.password == password181182183# Tests for different host types184185186def test_url_valid_host():
620 unmodified lines
modified:CHANGELOG.md+6 added
2 unmodified lines
3All notable changes to this project will be documented in this file.45The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).67## Unreleased89### Fixed1011* Allow URLs where username or password contains unescaped '@'. (#2986)1213## 0.25.2 (24th November, 2023)1415### Added16
1044 unmodified lines