#396 Update hubs/widgets/validators.py for Link validation[solves #352]
Closed 6 years ago by dristybutola. Opened 6 years ago by dristybutola.
dristybutola/fedora-hubs develop  into  develop

file modified
+11 -1
@@ -41,7 +41,17 @@ 

  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):

This validation regex works for url using http, https , localhost and ip address.
Issue url:https://pagure.io/fedora-hubs/issue/352

Pull-Request has been closed by dristybutola

6 years ago
Metadata