From 76e4ee94cea880ca1f605bf0824dc3f3cde88491 Mon Sep 17 00:00:00 2001 From: Hidden Z Date: Fri, 22 Oct 2010 17:47:27 +0000 Subject: [PATCH] validation.py: add hostname lenght check That's not really needed, just added for avoiding django.db.utils.DatabaseError exceptions when trying to add too long hostname with py-i2phosts-injector --- web/lib/validation.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/web/lib/validation.py b/web/lib/validation.py index 6fbb5d6..dc65bcf 100644 --- a/web/lib/validation.py +++ b/web/lib/validation.py @@ -13,6 +13,10 @@ def validate_hostname(data): """ # convert hostname to lowercase and strip leading and trailing whitespaces data = data.lower().strip() + # do lenght check here for avoiding django.db.utils.DatabaseError exceptions + # when trying to add too long hostname with py-i2phosts-injector + if len(data) > 67: + raise forms.ValidationError('Too long hostname (should be 67 chars max)') # Must end with '.i2p'. if re.match(r'.*\.i2p$', data) == None: raise forms.ValidationError('Hostname doesn\'t ends with .i2p')