diff --git a/frappe/model/base_document.py b/frappe/model/base_document.py index cf63aa98b6..05435482bd 100644 --- a/frappe/model/base_document.py +++ b/frappe/model/base_document.py @@ -667,6 +667,9 @@ class BaseDocument(object): frappe.utils.validate_phone_number(data, throw=True) if data_field_options == "URL": + if not data: + continue + frappe.utils.validate_url(data, throw=True) def _validate_constants(self): diff --git a/frappe/tests/test_utils.py b/frappe/tests/test_utils.py index ebba60b8e8..20d2bf127c 100644 --- a/frappe/tests/test_utils.py +++ b/frappe/tests/test_utils.py @@ -3,8 +3,10 @@ from __future__ import unicode_literals import unittest +import frappe from frappe.utils import evaluate_filters, money_in_words, scrub_urls, get_url +from frappe.utils import validate_url, validate_email_address from frappe.utils import ceil, floor from PIL import Image @@ -54,14 +56,15 @@ class TestMoney(unittest.TestCase): for num in nums_bhd: self.assertEqual( - money_in_words(num[0], "BHD"), num[1], "{0} is not the same as {1}". - format(money_in_words(num[0], "BHD"), num[1]) + money_in_words(num[0], "BHD"), + num[1], + "{0} is not the same as {1}".format(money_in_words(num[0], "BHD"), num[1]) ) for num in nums_ngn: self.assertEqual( - money_in_words(num[0], "NGN"), num[1], "{0} is not the same as {1}". - format(money_in_words(num[0], "NGN"), num[1]) + money_in_words(num[0], "NGN"), num[1], + "{0} is not the same as {1}".format(money_in_words(num[0], "NGN"), num[1]) ) class TestDataManipulation(unittest.TestCase): @@ -93,7 +96,7 @@ class TestDataManipulation(unittest.TestCase): class TestMathUtils(unittest.TestCase): def test_floor(self): from decimal import Decimal - self.assertEqual(floor(2), 2 ) + self.assertEqual(floor(2), 2) self.assertEqual(floor(12.32904), 12) self.assertEqual(floor(22.7330), 22) self.assertEqual(floor('24.7'), 24) @@ -102,7 +105,7 @@ class TestMathUtils(unittest.TestCase): def test_ceil(self): from decimal import Decimal - self.assertEqual(ceil(2), 2 ) + self.assertEqual(ceil(2), 2) self.assertEqual(ceil(12.32904), 13) self.assertEqual(ceil(22.7330), 23) self.assertEqual(ceil('24.7'), 25) @@ -127,6 +130,44 @@ class TestHTMLUtils(unittest.TestCase): self.assertTrue('