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

Check whether an EncodedURL can be decoded before giving it back #178

Open
wants to merge 4 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/hyperlink/hypothesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

from . import DecodedURL, EncodedURL

from hypothesis import assume
from hypothesis import reject
from hypothesis.strategies import (
composite,
integers,
Expand Down Expand Up @@ -137,7 +137,7 @@ def idna_text(draw, min_size=1, max_size=None):
try:
idna_encode(result)
except IDNAError:
assume(False)
reject()

return result

Expand Down Expand Up @@ -198,7 +198,7 @@ def hostname_labels(draw, allow_idn=True):
try:
check_label(label)
except UnicodeError: # pragma: no cover (not always drawn)
assume(False)
reject()

return label

Expand Down Expand Up @@ -318,4 +318,8 @@ def decoded_urls(draw):
Call the L{EncodedURL.to_uri} method on each URL to get an HTTP
protocol-friendly URI.
"""
return DecodedURL(draw(encoded_urls()))
encoded_url = draw(encoded_urls())
try:
return DecodedURL(encoded_url)
except UnicodeDecodeError:
reject()
8 changes: 8 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,15 @@ basepython = {[default]basepython}
skip_install = True

deps =
# Pin black and all of its dependencies so an incompatible release of one
# of them doesn't break this environment.
appdirs==1.4.4
black==21.7b0
click==7.1.2
mypy-extensions==0.4.3
pathspec==0.9.0
regex==2022.8.17
tomli==1.2.3

setenv =
BLACK_LINT_ARGS=--check
Expand Down