From 0cb001512733eaf087d8137a1f08e09290132b06 Mon Sep 17 00:00:00 2001 From: Aevann Date: Fri, 6 Oct 2023 19:51:23 +0300 Subject: [PATCH] fix reddit user /s/ links without having to visit them --- files/helpers/regex.py | 3 ++- files/helpers/sanitize.py | 2 ++ files/routes/posts.py | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/files/helpers/regex.py b/files/helpers/regex.py index ed6d841cb..159fe0783 100644 --- a/files/helpers/regex.py +++ b/files/helpers/regex.py @@ -182,11 +182,12 @@ search_regex_3 = re.compile(r'\s+', flags=re.A) #sanitizing reddit_mention_regex = re.compile('(?|")https:\/\/old.reddit.com\/(r|user)\/', flags=re.A) diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 66f7092c5..84fb0b319 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -764,6 +764,8 @@ def normalize_url(url): url = url.replace("reddit.com/u/", "reddit.com/user/") + url = reddit_s_url_user_regex.sub(r'https://old.reddit.com/\2', url) + url = reddit_domain_regex.sub(r'\1https://old.reddit.com/\3', url) url = url.replace("https://music.youtube.com/watch?v=", "https://youtube.com/watch?v=") \ diff --git a/files/routes/posts.py b/files/routes/posts.py index 4bd223791..e49c5970e 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -294,12 +294,12 @@ def surl_and_thumbnail_thread(post_url, post_body, post_body_html, pid, generate #s_url dirty = False - if post_url and reddit_s_url_regex.fullmatch(post_url): + if post_url and reddit_s_url_sub_regex.fullmatch(post_url): post_url = reddit_s_url_cleaner(post_url) dirty = True if post_body: - for i in reddit_s_url_regex.finditer(post_body): + for i in reddit_s_url_sub_regex.finditer(post_body): old = i.group(0) new = reddit_s_url_cleaner(old) post_body = post_body.replace(old, new)