From b0e76daceb34933e77914b7eb63c04118427b9fe Mon Sep 17 00:00:00 2001 From: Tao Sauvage Date: Tue, 21 Feb 2017 07:35:52 +0100 Subject: [PATCH] Temp fix for domain regex (Fix #59). --- hrt/util.py | 2 +- tests/test_url.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/hrt/util.py b/hrt/util.py index 47c5629..b059b31 100644 --- a/hrt/util.py +++ b/hrt/util.py @@ -6,4 +6,4 @@ re_ipv4_address = re.compile('^(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$') re_ipv6_address = re.compile('^(?:(?:[0-9A-Fa-f]{1,4}:){6}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))|::(?:[0-9A-Fa-f]{1,4}:){5}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))|(?:[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){4}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))|(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){3}(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:[0-9]|[1-9][0-9]|1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', re.IGNORECASE) diff --git a/tests/test_url.py b/tests/test_url.py index 8652a0b..c37a52a 100644 --- a/tests/test_url.py +++ b/tests/test_url.py @@ -26,6 +26,12 @@ def test_check_valid_url(self): self.assertTrue(url.check_valid_url("http://www.cmd5.com")) self.assertTrue(url.check_valid_url("https://www-cmd5.com")) + # Regression for https://github.com/owtf/http-request-translator/issues/59 + self.assertTrue(url.check_valid_url('http://9gag.com')) + self.assertTrue(url.check_valid_url('https://9gag.com')) + self.assertTrue(url.check_valid_url('http://gag9.com')) + self.assertTrue(url.check_valid_url('https://gag9.com')) + ### # url.check_valid_port ###