From 7e25ed039a65dc4f51a8f5ddac547cdf99e59298 Mon Sep 17 00:00:00 2001 From: funilrys Date: Wed, 26 Jul 2023 15:06:21 +0200 Subject: [PATCH] Ensure that hostnames without dots are excluded. This patch fixes #2347. --- testUpdateHostsFile.py | 1 + updateHostsFile.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/testUpdateHostsFile.py b/testUpdateHostsFile.py index 12fe695fb96..7b3ff3a49f6 100644 --- a/testUpdateHostsFile.py +++ b/testUpdateHostsFile.py @@ -842,6 +842,7 @@ def test_no_match(self): "128.0.0.1", "0.0.0 google", "0.1.2.3.4 foo/bar", + "0.0.0.0 https" ]: self.assertEqual(normalize_rule(rule, **kwargs), (None, None)) diff --git a/updateHostsFile.py b/updateHostsFile.py index 5c8271492cf..986f2023a37 100755 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -1061,7 +1061,7 @@ def normalize_response( """ first try: IP followed by domain """ - regex = r"^\s*(\d{1,3}\.){3}\d{1,3}\s+([\w\.-]+[a-zA-Z])(.*)" + regex = r"^\s*(\d{1,3}\.){3}\d{1,3}\s+((?:\w+\.)+[a-zA-Z]+)(.*)" result = re.search(regex, rule) if result: @@ -1090,7 +1090,7 @@ def normalize_response( """ # deny any potential IPv6 address here. if ":" not in rule: - regex = r"^\s*([\w\.-]+[a-zA-Z])(.*)" + regex = r"^\s*((?:\w+\.)+[a-zA-Z]+)(.*)" result = re.search(regex, rule) if result: