From 28786342dc2a264f807c98e6ea3d8720a3999c5c Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 2 Jul 2022 02:25:58 +0200 Subject: [PATCH] fix snappy archiving images --- files/helpers/sanitize.py | 7 ++++--- files/routes/posts.py | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 5589d276a..cb13aec69 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -215,9 +215,10 @@ def sanitize(sanitized, edit=False): tag['alt'] = f'![]({tag["data-src"]})' tag['referrerpolicy'] = "no-referrer" - a = soup.new_tag("a", href=tag["data-src"], rel="nofollow noopener noreferrer") - tag = tag.replace_with(a) - a.append(tag) + if tag.parent.name != 'a': + a = soup.new_tag("a", href=tag["data-src"], rel="nofollow noopener noreferrer") + tag = tag.replace_with(a) + a.append(tag) for tag in soup.find_all("a"): if tag.get("href") and fishylinks_regex.fullmatch(str(tag.string)): diff --git a/files/routes/posts.py b/files/routes/posts.py index 9cccdabdd..45a7d2c46 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -1135,9 +1135,10 @@ def submit_post(v, sub=None): gevent.spawn(archiveorg, newposturl) captured = [] - for i in list(snappy_url_regex.finditer(post.body_html)): - if i.group(0) in captured: continue - captured.append(i.group(0)) + body_for_snappy = post.body_html.replace(' data-src="', ' src="') + for i in list(snappy_url_regex.finditer(body_for_snappy)): + if i.group(1) in captured: continue + captured.append(i.group(1)) href = i.group(1) if not href: continue