From 4cd81b390a42b3e21ac52d65bc5c6762962a61c7 Mon Sep 17 00:00:00 2001 From: xkww3n Date: Sun, 15 Oct 2023 23:38:22 +0800 Subject: [PATCH] Tidy up is_domain func. --- Utils/rule.py | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/Utils/rule.py b/Utils/rule.py index ea38542..c9f68ba 100644 --- a/Utils/rule.py +++ b/Utils/rule.py @@ -66,28 +66,14 @@ def is_ipaddr(addr: str) -> bool: def is_domain(rule: Filter) -> bool: + blacklist_include = ("/", "*", "=", "~", "?", "#", ",", ":", " ", "(", ")", "[", "]", "_") if ( rule.type == "filter" and rule.selector["type"] == "url-pattern" and "." in rule.text - and "/" not in rule.text - and "*" not in rule.text - and "=" not in rule.text - and "~" not in rule.text - and "?" not in rule.text - and "#" not in rule.text - and "," not in rule.text - and ":" not in rule.text - and " " not in rule.text - and ("(" or ")") not in rule.text - and not rule.text.startswith("_") + and not any([bl_char in rule.text for bl_char in blacklist_include]) and not rule.text.startswith("-") - and not rule.text.startswith("^") - and not rule.text.startswith("[") and not rule.text.endswith(".") - and not rule.text.endswith("_") - and not rule.text.endswith("]") - and not rule.text.endswith(";") and not rule.options and not is_ipaddr(rule.text.strip("||").strip("^")) ):