From 646bcdf7be542af334b10d1b66bcbaa6ec1b159c Mon Sep 17 00:00:00 2001 From: freamon Date: Sat, 21 Sep 2024 21:03:08 +0000 Subject: [PATCH] avoid wrapping anchors around existing anchors (e.g. if raw URL already wrapped by remote PieFed instance) --- app/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/utils.py b/app/utils.py index e0199917..5ddc8819 100644 --- a/app/utils.py +++ b/app/utils.py @@ -284,6 +284,10 @@ def allowlist_html(html: str, a_target='_blank') -> str: clean_html = str(soup) + # avoid wrapping anchors around existing anchors (e.g. if raw URL already wrapped by remote PieFed instance) + re_double_anchor = re.compile(r'(.*?<\/a>)<\/a>') + clean_html = re_double_anchor.sub(r'\1', clean_html) + # avoid returning empty anchors re_empty_anchor = re.compile(r'<\/a>') clean_html = re_empty_anchor.sub(r'\1', clean_html)