Correct 2nd Iter: Hostnames to lowercase.
authorfunilrys <redacted>
Thu, 7 Sep 2023 16:46:54 +0000 (18:46 +0200)
committerfunilrys <redacted>
Thu, 7 Sep 2023 16:46:54 +0000 (18:46 +0200)
As mentioned by @StevenBlack in #2400, hostnames should be
converted to lowercase.

testUpdateHostsFile.py
updateHostsFile.py

index b519dc69c551b01c4d955d32f830ff2d2e87e9ba..69a90984c29ba69793e8d2c0c8ae0954b824698c 100644 (file)
@@ -854,6 +854,25 @@ class TestNormalizeRule(BaseStdout):
             expected = "==>" + rule + "<=="
             self.assertIn(expected, output)
 
+    def test_mixed_cases(self):
+        for rule, expected_target in (
+            ("tWiTTer.cOM", "twitter.com"),
+            ("goOgLe.Com", "google.com"),
+            ("FoO.bAR.edu", "foo.bar.edu"),
+        ):
+            expected = (expected_target, "0.0.0.0 " + expected_target + "\n")
+
+            actual = normalize_rule(
+                rule, target_ip="0.0.0.0", keep_domain_comments=False
+            )
+            self.assertEqual(actual, expected)
+
+            # Nothing gets printed if there's a match.
+            output = sys.stdout.getvalue()
+            self.assertEqual(output, "")
+
+            sys.stdout = StringIO()
+
     def test_no_comments(self):
         for target_ip in ("0.0.0.0", "127.0.0.1", "8.8.8.8"):
             rule = "127.0.0.1 1.google.com foo"
index b925665bb7d6963d60be4821f7ee4b7db5db804e..291faa0a41e676aa5f95b29f21b71097f8e8e3fb 100755 (executable)
@@ -1123,6 +1123,8 @@ def normalize_rule(rule, target_ip, keep_domain_comments):
             # Example: 0.0.0.0 example.org
             hostname, suffix = split_rule[-1], None
 
+        hostname = hostname.lower()
+
         if (
             is_ip(hostname)
             or re.search(static_ip_regex, hostname)
@@ -1154,6 +1156,8 @@ def normalize_rule(rule, target_ip, keep_domain_comments):
         except ValueError:
             hostname, suffix = split_rule[0], None
 
+        hostname = hostname.lower()
+
         return normalize_response(hostname, suffix)
 
     return belch_unwanted(rule)
git clone https://git.99rst.org/PROJECT