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: hostname format check on empty string raises ValueError #1127

Commits on Jul 13, 2023

  1. 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 python-jsonschema#1121.
    jvtm committed Jul 13, 2023
    Configuration menu
    Copy the full SHA
    ce59652 View commit details
    Browse the repository at this point in the history