From 90120f7df72b0488da19416432cd7d1515fe27af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= Date: Tue, 16 Jan 2024 15:48:09 +0200 Subject: [PATCH 1/1] Fixed: Strip links in profile description The Featured Link is the only link that is supposed to appear in the profile. --- feeds.py | 4 ++-- settings.py | 2 +- subspace.py | 6 +++--- utils.py | 15 +++++++++++++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/feeds.py b/feeds.py index a20ec0c..1f5944c 100644 --- a/feeds.py +++ b/feeds.py @@ -739,7 +739,7 @@ def make_feed_page(session): else: if c_user and (c_user.info or c_user.url or c_user.flair): if c_user.info: - topinfo += c_user.info + '\n' + topinfo += clean_description(c_user.info) + '\n' if c_user.url: topinfo += f'=> {c_user.url}\n' if c_user.flair: @@ -747,7 +747,7 @@ def make_feed_page(session): topinfo += f'\n{flair}' elif context: if context.info: - topinfo += context.info + '\n' + topinfo += clean_description(context.info) + '\n' if context.url: topinfo += f'=> {context.url}\n' # Users moderating this subspace. diff --git a/settings.py b/settings.py index ba71d96..ef5f881 100644 --- a/settings.py +++ b/settings.py @@ -388,7 +388,7 @@ def make_settings_page(session): elif req.path == session.path + 'settings/info/' + token: if req.query == None: return 10, 'Enter profile description:' - db.update_user(session.user, info=clean_query(req)) + db.update_user(session.user, info=clean_description(clean_query(req))) return 30, '/settings/profile' elif req.path == session.path + 'settings/email': diff --git a/subspace.py b/subspace.py index d82140b..5ac1c41 100644 --- a/subspace.py +++ b/subspace.py @@ -247,7 +247,7 @@ def subspace_admin_actions(session, action): if action == 'info': if req.query == None: return 10, f"Description for {session.context.title()}:" - db.update_subspace(session.context, info=clean_title(clean_query(req)), actor_id=user.id) + db.update_subspace(session.context, info=clean_description(clean_query(req)), actor_id=user.id) return 30, admin_link if action == 'url': @@ -437,12 +437,12 @@ def make_search_page(session): if isinstance(obj, User): page += f'=> /u/{obj.name} {obj.avatar} u/{obj.name}\n' if obj.info: - page += f'{obj.info[:300].strip()}\n' + page += f'{clean_title(strip_links(obj.info))[:300].strip()}\n' elif isinstance(obj, Subspace): page += f'=> /s/{obj.name} s/{obj.name}\n' if obj.info: - page += f'{obj.info[:300].strip()}\n' + page += f'{clean_title(strip_links(obj.info))[:300].strip()}\n' elif isinstance(obj, Post): ctx = ("u/" if obj.sub_owner else "s/") + obj.sub_name diff --git a/utils.py b/utils.py index f7fb258..8ee2128 100644 --- a/utils.py +++ b/utils.py @@ -166,6 +166,21 @@ def clean_title(title): return title +def clean_description(desc): + # Strip links but keep other formatting. + cleaned = [] + pre = False + for line in desc.split('\n'): + line = line.strip() + if line.startswith('```'): + pre = not pre + if not pre: + if line.startswith('=>'): + continue + cleaned.append(line) + return '\n'.join(cleaned) + + def clean_tinylog(text): # Clean it up as per Tinylog specification. clean = [] -- 2.34.1