Skip to content
Myr

Just use default `safe=...` characters for `urlescape` (#3376)

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

authored by Tom Christie · committed by GitHub · parent 5440381 · Browse files · 2 files+3 added−17 removed
This commit

State

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

Diff stats

2 files+3 added−17 removed

  • tests:+2 added−2 removed
  • other:+1 added−15 removed

2 files+3 added−17 removed

modified:httpx/_urls.py+1 added-15 removed
10 unmodified lines
1112__all__ = ["URL", "QueryParams"]131415# To urlencode query parameters, we use the whatwg query percent-encode set16# and additionally escape U+0025 (%), U+0026 (&), U+002B (+) and U+003D (=).1718# https://url.spec.whatwg.org/#percent-encoded-bytes1920URLENCODE_SAFE = "".join(21 [22 chr(i)23 for i in range(0x20, 0x7F)24 if i not in (0x20, 0x22, 0x23, 0x25, 0x26, 0x2B, 0x3C, 0x3D, 0x3E)25 ]26)272815class URL:16 """17 url = httpx.URL("HTTPS://jo%40email.com:a%20secret@müller.de:1234/pa%20th?search=ab#anchorlink")18
585 unmodified lines
604 return False605 return sorted(self.multi_items()) == sorted(other.multi_items())606607 def __str__(self) -> str:622 return urlencode(self.multi_items(), safe=URLENCODE_SAFE)608 return urlencode(self.multi_items())609610 def __repr__(self) -> str:611 class_name = self.__class__.__name__612 query_string = str(self)
13 unmodified lines
modified:tests/models/test_url.py+2 added-2 removed
146 unmodified lines
147 url = httpx.URL("https://www.example.com/?a=b+c&d=e/f")148 assert url.raw_path == b"/?a=b+c&d=e/f"149150 url = httpx.URL("https://www.example.com/", params={"a": "b c", "d": "e/f"})151 assert url.raw_path == b"/?a=b+c&d=e/f"151 assert url.raw_path == b"/?a=b+c&d=e%2Ff"152153154def test_url_params():155 url = httpx.URL("https://example.org:123/path/to/somewhere", params={"a": "123"})
152 unmodified lines
308 # Params passed as form key-value pairs should always be escaped,309 # even if they include a valid escape sequence.310 # We want to match browser form behaviour here.311 url = httpx.URL("http://webservice", params={"u": "http://example.com?q=foo%2Fa"})312 assert str(url) == "http://webservice?u=http://example.com?q%3Dfoo%252Fa"312 assert str(url) == "http://webservice?u=http%3A%2F%2Fexample.com%3Fq%3Dfoo%252Fa"313314315# Tests for query parameter percent encoding.316#
547 unmodified lines