From 022fa0e75f4801006e1c7f95581e51e5f177b19e Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 26 Oct 2023 11:00:43 -0400 Subject: [PATCH] fix: don't count internal links towards link count when restricting new users from posting links --- src/posts/queue.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/posts/queue.js b/src/posts/queue.js index 8d6550b7fd..23419d2ee3 100644 --- a/src/posts/queue.js +++ b/src/posts/queue.js @@ -96,9 +96,16 @@ module.exports = function (Posts) { if (!isPrivileged && reputation < meta.config['min:rep:post-links']) { const parsed = await plugins.hooks.fire('filter:parse.raw', String(content)); - if (parsed.match(/]*>([^<]+)<\/a>/g)) { - return false; + const matches = parsed.matchAll(/]*href="([^"]+)"[^>]*>/g); + let external = 0; + for (const [, href] of matches) { + const internal = utils.isInternalURI(new URL(href, nconf.get('url')), new URL(nconf.get('url')), nconf.get('relative_path')); + if (!internal) { + external += 1; + } } + + return external === 0; } return true; };