From 3bb77da9e74e2ea83f07c109aa017c0bad0c2fdd Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Sat, 27 Aug 2022 11:20:00 -0400 Subject: [PATCH 1/4] Check whether an EncodedURL can be decoded before giving it back --- src/hyperlink/hypothesis.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/hyperlink/hypothesis.py b/src/hyperlink/hypothesis.py index 4ab987eb..a041ffe5 100644 --- a/src/hyperlink/hypothesis.py +++ b/src/hyperlink/hypothesis.py @@ -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: + assume(False) From 59998b5387081a4e8c1598f85251eda488126069 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Sat, 27 Aug 2022 11:32:31 -0400 Subject: [PATCH 2/4] handle only UnicodeDecodeError --- src/hyperlink/hypothesis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hyperlink/hypothesis.py b/src/hyperlink/hypothesis.py index a041ffe5..dc12db7a 100644 --- a/src/hyperlink/hypothesis.py +++ b/src/hyperlink/hypothesis.py @@ -321,5 +321,5 @@ def decoded_urls(draw): encoded_url = draw(encoded_urls()) try: return DecodedURL(encoded_url) - except: + except UnicodeDecodeError: assume(False) From d5ba6c84b5ad6d77669979866dd0d9620776f742 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Sat, 27 Aug 2022 11:35:07 -0400 Subject: [PATCH 3/4] Use the simpler and more easily analysed `reject` --- src/hyperlink/hypothesis.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hyperlink/hypothesis.py b/src/hyperlink/hypothesis.py index dc12db7a..3be47daf 100644 --- a/src/hyperlink/hypothesis.py +++ b/src/hyperlink/hypothesis.py @@ -31,7 +31,7 @@ from . import DecodedURL, EncodedURL - from hypothesis import assume + from hypothesis import reject from hypothesis.strategies import ( composite, integers, @@ -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 @@ -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 @@ -322,4 +322,4 @@ def decoded_urls(draw): try: return DecodedURL(encoded_url) except UnicodeDecodeError: - assume(False) + reject() From 3543eb03dc4a4958d58e471250c0aea6117376da Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Sat, 27 Aug 2022 11:41:37 -0400 Subject: [PATCH 4/4] Pin black's dependencies so it will work again --- tox.ini | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tox.ini b/tox.ini index 8865d178..56caefe6 100644 --- a/tox.ini +++ b/tox.ini @@ -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