From 0a5ea0cf253daba16f815876b7ceb35eabbddf26 Mon Sep 17 00:00:00 2001 From: tecc Date: Tue, 27 Sep 2022 21:11:27 +0200 Subject: [PATCH] change(tracking): More broad userpage filter --- plugins/track.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/plugins/track.js b/plugins/track.js index ce96eb8e2..188bb7e3d 100644 --- a/plugins/track.js +++ b/plugins/track.js @@ -21,20 +21,23 @@ function redact(redactor, base = defaultHandler) { }) } +const USER_AT = /^\/@.+/; +const USER_SUBPAGE = /^\/(u|card)\/.*/; + const TRACKER_OVERRIDES = [ { test(v) { - return /^\/@.+/.test(v); + return USER_AT.test(v) || USER_SUBPAGE.test(v); }, handling: redact((v) => { - const parts = v.pathname.split('/').filter((v) => v.length > 0); - for (const i in parts) { // NOTE(tecc): This might be overengineering but that's fine - const part = parts[i]; - if (/^@.+$/.test(part)) { - parts[i] = '@--redacted--'; - } + let pathname = v.pathname; + if (USER_AT.test(pathname)) { + pathname = pathname.replace(USER_AT, '/@--redacted--') } - v.pathname = '/' + parts.join('/'); + if (USER_SUBPAGE.test(pathname)) { + pathname = pathname.replace(USER_SUBPAGE, '/$1/--redacted--'); + } + v.pathname = pathname; return v; }) }