Skip to content

Local file URL validation #481

Description

@DUB1401

Fails to validate URL for local file:

from validators import url

url("file:///var/www") # ValidationError(func=url, args={'value': 'file:///var/www'})

Excpected True, because this URL type standartizated in RFC 8089.

Error in _validate_netloc() function. It expected domain like var.com, but see directory var.

ValidationError(
	func=hostname,
	args={'value': 'var', 'skip_ipv6_addr': True, 'skip_ipv4_addr': False, 'may_have_port': True, 'maybe_simple': False, 'consider_tld': False, 'private': None, 'rfc_1034': False, 'rfc_2782': False}
)

May be we should skip netloc validation in some cases like file and add file scheme in _validate_scheme() function.

Works this code, but is it correct behaviour for common URL scheme?

from validators import url

url("file:///var/www", simple_host = True, validate_scheme = lambda x: x == "file") # True

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions