python-validators/validators

URI with query string without equals sign is flagged as invalid

Closed this issue · 1 comments

It appears that with version 0.24, URIs with a query string that do not contain an equals sign are flagged as invalid. This appears to be more strict than what RFC 3986, section 3.4 prescribes.

For example, http://www.foo.example?bar is valid according to RFC 3986, but it is now flagged as invalid:

validators.url('http://www.foo.example?bar')

ValidationError(func=url, args={'reason': "bad query field: 'bar'", 'value': 'http://www.foo.example?bar'})

try:
if (
query
# ref: https://github.com/python/cpython/issues/117109
and parse_qs(query, strict_parsing=strict_query, separator="&")
and parse_qs(query, strict_parsing=strict_query, separator=";")
):
optional_segments &= True
except TypeError:
# for Python < v3.9.2 (official v3.10)
if query and parse_qs(query, strict_parsing=strict_query):
optional_segments &= True

Please pass strict_query=False. Query validation is performed internally by Python's parse_qs function.