Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion protovalidate/internal/extra_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,19 @@ def is_email(string: celtypes.Value) -> celpy.Result:

def is_uri(string: celtypes.Value) -> celpy.Result:
url = urlparse.urlparse(string)
if not all([url.scheme, url.netloc, url.path]):
# urlparse correctly reads the scheme from URNs but parses everything
# after (except the query string) as the path.
if url.scheme == "urn":
if not (url.path):
return celtypes.BoolType(False)
elif not all([url.scheme, url.netloc, url.path]):
return celtypes.BoolType(False)

# If the query string contains percent-encoding, then try to decode it.
# unquote will return the same string if it is improperly encoded.
if "%" in url.query:
return celtypes.BoolType(urlparse.unquote(url.query) != url.query)

return celtypes.BoolType(True)


Expand Down
Loading