From d9eb21932e9c854097720ef644fb0be33b651940 Mon Sep 17 00:00:00 2001 From: Hidden Z Date: Sun, 31 Oct 2010 12:24:28 +0000 Subject: [PATCH] web/lib/validation.py: add validate_i2purl() We need it for URL validation when adding external hosts sources. --- web/lib/validation.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/web/lib/validation.py b/web/lib/validation.py index 33b2365..656c2fe 100644 --- a/web/lib/validation.py +++ b/web/lib/validation.py @@ -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')