Browse Source

web/lib/validation.py: add validate_i2purl()

We need it for URL validation when adding external hosts sources.
pull/1/head
Hidden Z 14 years ago
parent
commit
d9eb21932e
  1. 9
      web/lib/validation.py

9
web/lib/validation.py

@ -109,3 +109,12 @@ def validate_b64hash(data, check_uniq=True): @@ -109,3 +109,12 @@ def validate_b64hash(data, check_uniq=True):
if qs.exists():
raise ValidationError('Base64 hash must be unique')
return data
def validate_i2purl(data):
""" Basic I2P URL validator """
# convert to lowercase and strip leading and trailing whitespaces
data = data.lower().strip()
# check for http://, .i2p in domain and GET validity
if re.match(r'^http://(?:.+?\.i2p)(?:/?|[/?]\S+)$', data) == None:
raise ValidationError('Bad I2P url')

Loading…
Cancel
Save