From 5b14bac4f69cc0164886ca587047301fb35a00c2 Mon Sep 17 00:00:00 2001 From: dristybutola Date: Oct 09 2017 05:13:57 +0000 Subject: [PATCH 1/8] 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): From 596189660b4f52760d3b5da7d07b4bbf1a4d2c6a Mon Sep 17 00:00:00 2001 From: dristybutola Date: Oct 09 2017 05:21:31 +0000 Subject: [PATCH 2/8] Update hubs/widgets/validators.py --- diff --git a/hubs/widgets/validators.py b/hubs/widgets/validators.py index a8d5037..0cd5c9b 100644 --- a/hubs/widgets/validators.py +++ b/hubs/widgets/validators.py @@ -16,6 +16,7 @@ import hubs.models import kitchen.text.converters import requests import six +import re def Required(value): From 1f857b99cf2f88cee14008fc0359eb121a821faf Mon Sep 17 00:00:00 2001 From: dristybutola Date: Oct 10 2017 09:17:22 +0000 Subject: [PATCH 3/8] Update hubs/widgets/validators.py --- diff --git a/hubs/widgets/validators.py b/hubs/widgets/validators.py index 0cd5c9b..ccbeb19 100644 --- a/hubs/widgets/validators.py +++ b/hubs/widgets/validators.py @@ -49,7 +49,8 @@ def Link(value): r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' r'(?::\d+)?' r'(?:/?|[/?]\S+)$',re.I) - if url: + + if url.search(value): return value else: raise ValueError('Invalid Url') From 7b8b568e85209e167155ce282a1462635f25262c Mon Sep 17 00:00:00 2001 From: dristybutola Date: Oct 10 2017 09:20:30 +0000 Subject: [PATCH 4/8] Update hubs/widgets/validators.py --- diff --git a/hubs/widgets/validators.py b/hubs/widgets/validators.py index ccbeb19..63e67ab 100644 --- a/hubs/widgets/validators.py +++ b/hubs/widgets/validators.py @@ -43,7 +43,7 @@ def Link(value): """Raises an error if the value doesn't look like a link.""" # TODO -- verify that this is actually a link url = re.compile( - r'^(?:http|ftp)s?://' # http:// or https:// + r'^(?:http|ftp)s?://' 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})' From b3f38438359cf2124e9e0ceff7c031d92a0dd61b Mon Sep 17 00:00:00 2001 From: dristybutola Date: Oct 10 2017 09:25:27 +0000 Subject: [PATCH 5/8] Update hubs/widgets/validators.py --- diff --git a/hubs/widgets/validators.py b/hubs/widgets/validators.py index 63e67ab..5954242 100644 --- a/hubs/widgets/validators.py +++ b/hubs/widgets/validators.py @@ -41,7 +41,7 @@ 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 + url = re.compile( r'^(?:http|ftp)s?://' r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' From 7fb251ca557257d2f867f8b4bea4a3bfc3de9cff Mon Sep 17 00:00:00 2001 From: dristybutola Date: Oct 10 2017 09:29:53 +0000 Subject: [PATCH 6/8] Update hubs/widgets/validators.py --- diff --git a/hubs/widgets/validators.py b/hubs/widgets/validators.py index 5954242..a7dc222 100644 --- a/hubs/widgets/validators.py +++ b/hubs/widgets/validators.py @@ -18,7 +18,15 @@ import requests import six import re - +#compiling regex for url validation +url = re.compile( + r'^(?:http|ftp)s?://' + 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) + def Required(value): """Raises an error if the value is ``False``-like.""" if not bool(value): @@ -41,15 +49,6 @@ def Integer(value): def Link(value): """Raises an error if the value doesn't look like a link.""" - - url = re.compile( - r'^(?:http|ftp)s?://' - 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.search(value): return value else: From 91ab1b1dda541805dc518c964a5a7ca573aaa086 Mon Sep 17 00:00:00 2001 From: dristybutola Date: Oct 11 2017 11:38:09 +0000 Subject: [PATCH 7/8] Update hubs/tests/test_widget_validators.py --- diff --git a/hubs/tests/test_widget_validators.py b/hubs/tests/test_widget_validators.py index d421aa5..d2f46bf 100644 --- a/hubs/tests/test_widget_validators.py +++ b/hubs/tests/test_widget_validators.py @@ -19,10 +19,9 @@ class ValidatorsTest(APPTest): self.assertEqual(validators.Integer("1"), 1) self.assertRaises(ValueError, validators.Integer, "text") - @unittest.skip("Not implemented yet") def test_link(self): - value = 'dummy' - self.assertEqual(validators.Link.from_string(value), value) + value = "https://pagure.io" + self.assertEqual(validators.value, value) self.assertRaises(ValueError, validators.Link, "text") def test_username(self): From e63375937990735408cd28f520664616670580dc Mon Sep 17 00:00:00 2001 From: dristybutola Date: Oct 11 2017 12:32:24 +0000 Subject: [PATCH 8/8] Update hubs/widgets/validators.py --- diff --git a/hubs/widgets/validators.py b/hubs/widgets/validators.py index a7dc222..f63fbcc 100644 --- a/hubs/widgets/validators.py +++ b/hubs/widgets/validators.py @@ -20,7 +20,7 @@ import re #compiling regex for url validation url = re.compile( - r'^(?:http|ftp)s?://' + r'^(?:http|ftp)s?://|\bwww.\b' 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})'