From f2049abaf8f899256e832d80a5387e3c799aea1e Mon Sep 17 00:00:00 2001 From: xemeds Date: Sun, 16 Aug 2020 21:35:02 +0300 Subject: [PATCH] Made the url validators case-insensitive --- tiny0/forms.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tiny0/forms.py b/tiny0/forms.py index 23cc2e6..fe55f67 100644 --- a/tiny0/forms.py +++ b/tiny0/forms.py @@ -15,12 +15,12 @@ def validate_URL(form, field): raise ValidationError("Invalid URL") # If the url starts with a dot after http:// or after https:// or just starts with a dot - if field.data.startswith("http://.") or field.data.startswith("https://.") or field.data.startswith("."): + if field.data.lower().startswith("http://.") or field.data.lower().startswith("https://.") or field.data.startswith("."): # Raise a ValidationError raise ValidationError("Invalid URL") # If the url starts with a slash after http:// or after https:// or just starts with a slash - if field.data.startswith("http:///") or field.data.startswith("https:///") or field.data.startswith("/"): + if field.data.lower().startswith("http:///") or field.data.lower().startswith("https:///") or field.data.startswith("/"): # Raise a ValidationError raise ValidationError("Invalid URL") @@ -30,12 +30,12 @@ def validate_URL(form, field): raise ValidationError("Invalid URL") # If the url contains the websites domain - if WEBSITE_DOMAIN in field.data: + if WEBSITE_DOMAIN in field.data.lower(): # Raise a ValidationError raise ValidationError("Invalid URL") # If the URL does not start with http:// and https:// - if not(field.data.startswith("http://")) and not(field.data.startswith("https://")): + if not(field.data.lower().startswith("http://")) and not(field.data.lower().startswith("https://")): # Add http:// to the beginning of the URL field.data = "http://" + field.data