2nd Iter: Ensure that hostnames without dots are excluded.
authorfunilrys <redacted>
Sat, 5 Aug 2023 18:39:41 +0000 (20:39 +0200)
committerfunilrys <redacted>
Sat, 5 Aug 2023 18:43:10 +0000 (20:43 +0200)
This patch fixes #2347.

Indeed, my previous patch was missing domains with dashes (-).

testUpdateHostsFile.py
updateHostsFile.py

index 7b3ff3a49f6d47ff6d82f5bd0405e1f0f758d0be..33b820fe1edee3b87de76c3ce16290ff1e7b9423 100644 (file)
@@ -842,7 +842,7 @@ class TestNormalizeRule(BaseStdout):
             "128.0.0.1",
             "0.0.0 google",
             "0.1.2.3.4 foo/bar",
-            "0.0.0.0 https"
+            "0.0.0.0 https",
         ]:
             self.assertEqual(normalize_rule(rule, **kwargs), (None, None))
 
@@ -905,7 +905,7 @@ class TestNormalizeRule(BaseStdout):
             sys.stdout = StringIO()
 
     def test_no_comment_raw(self):
-        for rule in ("twitter.com", "google.com", "foo.bar.edu"):
+        for rule in ("twitter.com", "google.com", "foo.bar.edu", "www.example-foo.bar.edu"):
             expected = (rule, "0.0.0.0 " + rule + "\n")
 
             actual = normalize_rule(
index 5c8271492cf70845f40d87437ee5914910ce4847..6a96878e92aaa97b49f44e8b8ef3e7e3d89529f7 100755 (executable)
@@ -1061,7 +1061,7 @@ def normalize_rule(rule, target_ip, keep_domain_comments):
     """
     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_rule(rule, target_ip, keep_domain_comments):
     """
     # 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:
git clone https://git.99rst.org/PROJECT