From 1649879a6979b6dc832e37b52bd5970978a138fd Mon Sep 17 00:00:00 2001 From: Aevann Date: Fri, 22 Sep 2023 09:51:45 +0300 Subject: [PATCH] better solution to the transform question --- files/helpers/sanitize.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 37e55f3cc..f97298d45 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -582,6 +582,8 @@ def sanitize(sanitized, golden=True, limit_pings=0, showmore=False, count_emojis #doing this here cuz of the linkifyfilter right above it (therefore unifying all link processing logic) soup = BeautifulSoup(sanitized, 'lxml') + has_transform = bool(soup.select('[style*=transform]')) + links = soup.find_all("a") if g.v and g.v.admin_level >= PERMS["IGNORE_DOMAIN_BAN"]: @@ -645,10 +647,8 @@ def sanitize(sanitized, golden=True, limit_pings=0, showmore=False, count_emojis link["target"] = "_blank" link["rel"] = "nofollow noopener" - for child in link.findChildren(): - if 'transform' in child.get("style", "").lower(): - del link["href"] - break + if has_transform: + del link["href"] sanitized = str(soup).replace('','').replace('','').replace('/>','>')