From 5b14bac4f69cc0164886ca587047301fb35a00c2 Mon Sep 17 00:00:00 2001 From: dristybutola Date: Oct 09 2017 05:13:57 +0000 Subject: Update hubs/widgets/validators.py for Link validation --- diff --git a/hubs/widgets/validators.py b/hubs/widgets/validators.py index f8c5b8f..a8d5037 100644 --- a/hubs/widgets/validators.py +++ b/hubs/widgets/validators.py @@ -41,7 +41,17 @@ def Integer(value): def Link(value): """Raises an error if the value doesn't look like a link.""" # TODO -- verify that this is actually a link - return value + url = re.compile( + r'^(?:http|ftp)s?://' # http:// or https:// + r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' + r'localhost|' + r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' + r'(?::\d+)?' + r'(?:/?|[/?]\S+)$',re.I) + if url: + return value + else: + raise ValueError('Invalid Url') def Username(value):