From ce59652c4358cc4c9e35c3c17bc98cbf20b104b5 Mon Sep 17 00:00:00 2001 From: Jyrki Muukkonen Date: Thu, 13 Jul 2023 12:17:06 +0300 Subject: [PATCH] fix: hostname format check on empty string raises ValueError Doing hostname format check on empty string seems to raise a ValueError: >>> from jsonschema.validators import validator_for >>> schema = {"$schema": "https://json-schema.org/draft/2020-12/schema", "type": "string", "format": "hostname"} >>> vcls = validator_for(schema) >>> validator = vcls(schema, format_checker=vcls.FORMAT_CHECKER) >>> list(validator.iter_errors("")) ... File "lib/python3.10/site-packages/jsonschema/_format.py", line 276, in is_host_name return FQDN(instance).is_valid File "lib/python3.10/site-packages/fqdn/__init__.py", line 44, in __init__ raise ValueError("fqdn must be str") ValueError: fqdn must be str Fix by adding `raises=ValueError` to the related `@_checks_drafts` decorator call. See also json-schema-org/JSON-Schema-Test-Suite#677. Fixes #1121. --- jsonschema/_format.py | 1 + 1 file changed, 1 insertion(+) diff --git a/jsonschema/_format.py b/jsonschema/_format.py index 2231f5e05..4f78110e0 100644 --- a/jsonschema/_format.py +++ b/jsonschema/_format.py @@ -270,6 +270,7 @@ def is_ipv6(instance: object) -> bool: draft7="hostname", draft201909="hostname", draft202012="hostname", + raises=ValueError, ) def is_host_name(instance: object) -> bool: if not isinstance(instance, str):