From 080d276bb71cc68777ae583f3a61e06af72e9f39 Mon Sep 17 00:00:00 2001 From: Steven Black Date: Mon, 16 Dec 2024 20:53:49 -0400 Subject: [PATCH] =?UTF-8?q?Issue=20#2785:=20fix=20=E2=80=94=20ignore=20dom?= =?UTF-8?q?ains=20ending=20with=20a=20dot.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- testUpdateHostsFile.py | 1 + updateHostsFile.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/testUpdateHostsFile.py b/testUpdateHostsFile.py index 4f580f2e2..3dfa76f43 100644 --- a/testUpdateHostsFile.py +++ b/testUpdateHostsFile.py @@ -846,6 +846,7 @@ class TestNormalizeRule(BaseStdout): "0.3.4.5 example.org/hello/world", "0.0.0.0 https", "0.0.0.0 https..", + "0.0.0.0 foo.", ]: self.assertEqual(normalize_rule(rule, **kwargs), (None, None)) diff --git a/updateHostsFile.py b/updateHostsFile.py index c31ed79bd..059cb731c 100755 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -1129,8 +1129,9 @@ def normalize_rule(rule, target_ip, keep_domain_comments): is_ip(hostname) or re.search(static_ip_regex, hostname) or "." not in hostname - or "/" in hostname or ".." in hostname + or "." in hostname[-1] + or "/" in hostname or ":" in hostname ): # Example: 0.0.0.0 127.0.0.1 @@ -1138,6 +1139,9 @@ def normalize_rule(rule, target_ip, keep_domain_comments): # If the hostname is: # - an IP - or looks like it, # - doesn't contain dots, or + # - contains repeated dots, + # - ends in a dot, or + # - contains a slash, or # - contains a colon, # we don't want to normalize it. return belch_unwanted(rule)