# Note: "Bare"- Domains are accepted. IP are excluded.
for rule in [
"128.0.0.1",
+ "::1",
+ "0.0.0.0 128.0.0.2",
"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))
sys.stdout = StringIO()
def test_no_comment_raw(self):
- for rule in ("twitter.com", "google.com", "foo.bar.edu", "www.example-foo.bar.edu", "www.example-3045.foobar.com"):
+ for rule in ("twitter.com", "google.com", "foo.bar.edu", "www.example-foo.bar.edu", "www.example-3045.foobar.com", "www.example.xn--p1ai"):
expected = (rule, "0.0.0.0 " + rule + "\n")
actual = normalize_rule(
"""
first try: IP followed by domain
"""
- regex = r"^\s*(\d{1,3}\.){3}\d{1,3}\s+((?:\w+\.)+[a-zA-Z\.-]+)(.*)"
+
+ # WARNING:
+ # [a-zA-Z0-9\-]+ is NOT an issue. (e.g., xn--p1ai TLD - and others).
+ regex = r"^\s*(\d{1,3}\.){3}\d{1,3}\s+((?:[\w\-\.]+\.)+[a-zA-Z0-9\-]+)(.*)"
result = re.search(regex, rule)
if result:
"""
# deny any potential IPv6 address here.
if ":" not in rule:
- regex = r"^\s*((?:\w+\.)+[a-zA-Z\.-]+)(.*)"
+ # WARNING:
+ # [a-zA-Z0-9\-]+ is NOT an issue. (e.g., xn--p1ai TLD - and others).
+ regex = r"^\s*((?:[\w\-\.]+\.)+[a-zA-Z0-9\-]+)(.*)"
result = re.search(regex, rule)
if result: