summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Kim <git@jasonk.me>2021-04-22 23:32:31 -0700
committerJason Kim <git@jasonk.me>2021-04-22 23:32:31 -0700
commit8e11c4885074b2029ec3705415f0191826eaf3ef (patch)
treef34fb3997e1f302d0903819a4d43903f69c6694e
parente3df6c4333c107240a45d6fbad933b54caa11139 (diff)
downloadprivacy-redirect-8e11c4885074b2029ec3705415f0191826eaf3ef.tar.gz
privacy-redirect-8e11c4885074b2029ec3705415f0191826eaf3ef.tar.bz2
privacy-redirect-8e11c4885074b2029ec3705415f0191826eaf3ef.zip
fix: add comments prefix for /foo/
Links that end in trailing slash but don't have "/comments/" should add "/comments" prefix but don't because the regex match succeeds. Fix the regular expression to be more robust and add prefix for paths like - /foo/ - /////foo - /foo///// - ////foo//// and not add prefix for paths like - /comments/foo - /////comments/foo - /comments/////foo - ////comments////foo - ////comments////foo/////
-rw-r--r--src/pages/background/background.js15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/pages/background/background.js b/src/pages/background/background.js
index fd0d55a..4fa3693 100644
--- a/src/pages/background/background.js
+++ b/src/pages/background/background.js
@@ -485,13 +485,16 @@ function redirectReddit(url, initiator, type) {
} else if (url.host === "redd.it") {
if (
redditInstance.includes("teddit") &&
- !url.pathname.match(/^\/\S+\//)
+ !url.pathname.match(/^\/+[^\/]+\/+[^\/]/)
) {
- // As of 2021-04-22, redirects for teddit redd.it links don't work unless
- // the path starts with "/comments". It appears that all links that
- // don't start with "/comments" are interchangeable with the ones
- // that do start with "/comments", so manually add that prefix if it is
- // missing.
+ // As of 2021-04-22, redirects for teddit redd.it/foo links don't work.
+ // It appears that adding "/comments" as a prefix works, so manually add
+ // that prefix if it is missing. Even though redd.it/comments/foo links
+ // don't seem to work or exist, guard against affecting those kinds of
+ // paths.
+ //
+ // Note the difference between redd.it/comments/foo (doesn't work) and
+ // teddit.net/comments/foo (works).
return `${redditInstance}/comments${url.pathname}${url.search}`;
}
}