Skip to content
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

Fix httpx is not encoding with symbol '%s' (#3140) #3141

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions httpx/_urlparse.py
Expand Up @@ -424,13 +424,13 @@ def is_safe(string: str, safe: str = "/") -> bool:
"""
Determine if a given string is already quote-safe.
"""
NON_ESCAPED_CHARS = UNRESERVED_CHARACTERS + safe + "%"

# All characters must already be non-escaping or '%'
for char in string:
if char not in NON_ESCAPED_CHARS:
NON_ESCAPED_CHARS = UNRESERVED_CHARACTERS + safe
# All characters must already be non-escaping or valid percent-encoded
for index, char in enumerate(string):
if char not in NON_ESCAPED_CHARS and not PERCENT_ENCODED_REGEX.match(
string[index : index + 3]
):
return False

return True


Expand Down
2 changes: 2 additions & 0 deletions tests/models/test_url.py
Expand Up @@ -284,6 +284,8 @@ def test_url_leading_dot_prefix_on_relative_url():
def test_param_requires_encoding():
url = httpx.URL("http://webservice", params={"u": "with spaces"})
assert str(url) == "http://webservice?u=with%20spaces"
url = httpx.URL("http://webservice", params={"u": "%"})
assert str(url) == "http://webservice?u=%25"


def test_param_does_not_require_encoding():
Expand Down