Skip to content

Commit fd9330a

Browse files
author
Steve Ayers
committed
Additional checks
1 parent 67017bd commit fd9330a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

protovalidate/internal/extra_func.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,20 @@ def is_email(string: celtypes.Value) -> celpy.Result:
165165

166166
def is_uri(string: celtypes.Value) -> celpy.Result:
167167
url = urlparse.urlparse(string)
168-
if not all([url.scheme, url.netloc, url.path]):
169-
return celtypes.BoolType(False)
168+
# urlparse correctly reads the scheme from URNs but parses everything
169+
# after (except the query string) as the path.
170+
if url.scheme == "urn":
171+
if not (url.path):
172+
return celtypes.BoolType(False)
173+
else:
174+
if not all([url.scheme, url.netloc, url.path]):
175+
return celtypes.BoolType(False)
176+
177+
# If the query string contains percent-encoding, then try to decode it.
178+
# unquote will return the same string if it is improperly encoded.
179+
if "%" in url.query:
180+
return celtypes.BoolType(urlparse.unquote(url.query) != url.query)
181+
170182
return celtypes.BoolType(True)
171183

172184

0 commit comments

Comments
 (0)