Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct 2nd Iter: Hostnames to lowercase. #2433

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions testUpdateHostsFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,25 @@ def test_no_match(self):
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"
Expand Down
4 changes: 4 additions & 0 deletions updateHostsFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,8 @@ def belch_unwanted(unwanted: str) -> Tuple[None, None]:
# 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)
Expand Down Expand Up @@ -1154,6 +1156,8 @@ def belch_unwanted(unwanted: str) -> Tuple[None, None]:
except ValueError:
hostname, suffix = split_rule[0], None

hostname = hostname.lower()

return normalize_response(hostname, suffix)

return belch_unwanted(rule)
Expand Down