From 3b113df86a7cf65309cbf26e7bafc5eec21eb479 Mon Sep 17 00:00:00 2001 From: rainbownapkin Date: Thu, 21 May 2026 03:15:16 -0400 Subject: [PATCH] Fixed link-handling for self-referential links in chat --- src/utils/linkUtils.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/utils/linkUtils.js b/src/utils/linkUtils.js index 9e85870..76b8e45 100644 --- a/src/utils/linkUtils.js +++ b/src/utils/linkUtils.js @@ -14,6 +14,9 @@ GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see .*/ +//Config +const config = require('../../config.json'); + //NPM Imports const validator = require('validator');//No express here, so regular validator it is! const {sanitizeUrl} = require("@braintree/sanitize-url"); @@ -32,6 +35,15 @@ module.exports.cache = new Map(); module.exports.markLink = async function(dirtyLink){ const link = sanitizeUrl(dirtyLink); + //If this link is referencing this web server + if(link.match(new RegExp(`^${config.protocol}://${config.domain}`)) != null){ + //Lazily return it as a good link, since we know it'll at least return a good 404 page XP + return { + link, + type: "link" + } + } + //Check link cache for the requested link const cachedLink = module.exports.cache.get(link); @@ -105,4 +117,4 @@ module.exports.markLink = async function(dirtyLink){ //return the link return linkObj; -} \ No newline at end of file +}