diff --git a/content.py b/content.py index 98eff032a..7a0e56d70 100644 --- a/content.py +++ b/content.py @@ -20,6 +20,7 @@ from flags import is_pgp_encrypted from flags import contains_pgp_public_key from flags import is_float from flags import is_right_to_left_text +from utils import resembles_domain from utils import string_starts_with from utils import replace_strings from utils import data_dir @@ -1078,7 +1079,7 @@ def _add_mention(base_dir: str, word_str: str, http_prefix: str, return True # @nick@domain if not (possible_domain == 'localhost' or - '.' in possible_domain or + resembles_domain(possible_domain) or is_yggdrasil_address(possible_domain)): return False recipient_actor = \ diff --git a/daemon_post_moderator.py b/daemon_post_moderator.py index 30a0f9b7b..c10405d41 100644 --- a/daemon_post_moderator.py +++ b/daemon_post_moderator.py @@ -11,6 +11,7 @@ import os import errno import urllib.parse from socket import error as SocketError +from utils import resembles_domain from utils import string_starts_with from utils import data_dir from utils import delete_post @@ -247,7 +248,7 @@ def moderator_actions(self, path: str, calling_domain: str, cookie: str, else: # assume the text is a domain name if (not full_block_domain and - ('.' in moderation_domain or + (resembles_domain(moderation_domain) or is_yggdrasil_address(moderation_domain))): nickname = '*' full_block_domain = \ @@ -282,7 +283,7 @@ def moderator_actions(self, path: str, calling_domain: str, cookie: str, else: # assume the text is a domain name if (not full_block_domain and - ('.' in moderation_domain or + (resembles_domain(moderation_domain) or is_yggdrasil_address(moderation_domain))): nickname = '*' full_block_domain = moderation_domain.strip() diff --git a/daemon_post_profile.py b/daemon_post_profile.py index 30af7d1c9..6bb1ba8e6 100644 --- a/daemon_post_profile.py +++ b/daemon_post_profile.py @@ -23,6 +23,7 @@ from flags import is_premium_account from flags import is_moderator from timeFunctions import get_account_timezone from timeFunctions import set_account_timezone +from utils import resembles_domain from utils import is_yggdrasil_url from utils import is_yggdrasil_address from utils import data_dir @@ -2509,7 +2510,7 @@ def _profile_post_twitter_alt_domain(base_dir: str, fields: {}, new_twitter_domain = new_twitter_domain.split('://')[1] if '/' in new_twitter_domain: new_twitter_domain = new_twitter_domain.split('/')[0] - if '.' in new_twitter_domain or \ + if resembles_domain(new_twitter_domain) or \ is_yggdrasil_address(new_twitter_domain): set_config_param(base_dir, 'twitterdomain', new_twitter_domain) @@ -2531,7 +2532,7 @@ def _profile_post_youtube_alt_domain(base_dir: str, fields: {}, new_yt_domain = new_yt_domain.split('://')[1] if '/' in new_yt_domain: new_yt_domain = new_yt_domain.split('/')[0] - if '.' in new_yt_domain or \ + if resembles_domain(new_yt_domain) or \ is_yggdrasil_address(new_yt_domain): set_config_param(base_dir, 'youtubedomain', new_yt_domain) diff --git a/epicyon.py b/epicyon.py index 617f80206..d9d4986aa 100644 --- a/epicyon.py +++ b/epicyon.py @@ -75,6 +75,7 @@ from tests import test_update_actor from tests import run_all_tests from auth import store_basic_credentials from auth import create_password +from utils import resembles_domain from utils import string_starts_with from utils import is_yggdrasil_url from utils import is_yggdrasil_address @@ -4366,7 +4367,7 @@ def _command_options() -> None: yt_domain = yt_domain.split('://')[1] if '/' in yt_domain: yt_domain = yt_domain.split('/')[0] - if '.' in yt_domain or is_yggdrasil_address(yt_domain): + if resembles_domain(yt_domain) or is_yggdrasil_address(yt_domain): argb.yt_replace_domain = yt_domain twitter_domain = get_config_param(base_dir, 'twitterdomain') @@ -4375,7 +4376,8 @@ def _command_options() -> None: twitter_domain = twitter_domain.split('://')[1] if '/' in twitter_domain: twitter_domain = twitter_domain.split('/')[0] - if '.' in twitter_domain or is_yggdrasil_address(twitter_domain): + if resembles_domain(twitter_domain) or \ + is_yggdrasil_address(twitter_domain): argb.twitter_replacement_domain = twitter_domain if set_theme(base_dir, theme_name, domain, diff --git a/posts.py b/posts.py index 96750b113..0524e3070 100644 --- a/posts.py +++ b/posts.py @@ -45,6 +45,7 @@ from timeFunctions import date_utcnow from timeFunctions import date_from_string_format from timeFunctions import date_epoch from timeFunctions import valid_post_date +from utils import resembles_domain from utils import string_starts_with from utils import is_yggdrasil_address from utils import resembles_url @@ -2770,7 +2771,7 @@ def get_mentioned_people(base_dir: str, http_prefix: str, continue else: external_domain = handle.split('@')[1] - if not (('.' in external_domain or + if not ((resembles_domain(external_domain) or is_yggdrasil_address(external_domain)) or external_domain == 'localhost'): continue diff --git a/utils.py b/utils.py index 0b8116dbc..219a53ec9 100644 --- a/utils.py +++ b/utils.py @@ -4035,8 +4035,8 @@ def resembles_domain(text: str) -> bool: Why not use validators? It's so that exotic, potentially p2p domains may be used. """ - if ' ' in text or '-' in text or '<' in text or ';' in text or \ - '"' in text or '(' in text or ')' in text: + if ' ' in text or '/' in text or '-' in text or '<' in text or \ + ';' in text or '"' in text or '(' in text or ')' in text: return False # conventional domain