From: funilrys Date: Sun, 3 Sep 2023 11:12:41 +0000 (+0200) Subject: Remove any potential invalid entries. X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=8fc7f948a8bde016e3998621e22d89d448128879;p=stevenblack-hosts.git Remove any potential invalid entries. - Anything that looks like an IP will be ignored. - Anything that doesn't containt dots will be ignored. --- diff --git a/updateHostsFile.py b/updateHostsFile.py index 90b39df97..9b82e98c1 100755 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -1102,7 +1102,6 @@ def normalize_rule(rule, target_ip, keep_domain_comments): print("==>%s<==" % unwanted) return None, None - """ first try: IP followed by domain """ @@ -1124,16 +1123,30 @@ def normalize_rule(rule, target_ip, keep_domain_comments): # Example: 0.0.0.0 example.org hostname, suffix = split_rule[-1], None - if is_ip(hostname): + if ( + is_ip(hostname) + or re.search(static_ip_regex, split_rule[0]) + or "." not in hostname + or ":" in hostname + or "" + ): # Example: 0.0.0.0 127.0.0.1 - # If the hostname is an IP, we don't want to normalize it. + # If the hostname is: + # - an IP - or looks like it, + # - doesn't contain dots, or + # - contains a colon, + # we don't want to normalize it. return belch_unwanted(rule) return normalize_response(hostname, suffix) - if not re.search(static_ip_regex, split_rule[0]) and ":" not in split_rule[0]: - # Deny anything that looks like an IP. + if ( + not re.search(static_ip_regex, split_rule[0]) + and ":" not in split_rule[0] + and "." in split_rule[0] + ): + # Deny anything that looks like an IP & doesn't container dots. try: hostname, suffix = split_rule