From 06c38247402948b758c98697129d04899d2bc092 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 13 Aug 2025 14:41:44 -0400 Subject: [PATCH] fix: regression caused by cc6fd49c4d2ddc6970ea23011dece5ba91517ec0 --- src/posts/parse.js | 13 +++---------- test/posts.js | 8 ++++---- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/posts/parse.js b/src/posts/parse.js index f2017c2106..46efafb0d6 100644 --- a/src/posts/parse.js +++ b/src/posts/parse.js @@ -88,16 +88,9 @@ module.exports = function (Posts) { while (current !== null) { if (current[1]) { try { - parsed = new URL(current[1]); - if (!parsed.protocol) { - if (current[1].startsWith('/')) { - // Internal link - absolute = nconf.get('base_url') + current[1]; - } else { - // External link - absolute = `//${current[1]}`; - } - + parsed = new URL(current[1], nconf.get('url')); + absolute = parsed.toString(); + if (absolute !== current[1]) { const offset = current[0].indexOf(current[1]); content = content.slice(0, current.index + offset) + absolute + diff --git a/test/posts.js b/test/posts.js index 2fc22904fc..4fce2f2ff5 100644 --- a/test/posts.js +++ b/test/posts.js @@ -763,18 +763,18 @@ describe('Post\'s', () => { it('should turn relative links in post body to absolute urls', (done) => { const nconf = require('nconf'); - const content = 'test youtube'; + const content = 'test youtube'; const parsedContent = posts.relativeToAbsolute(content, posts.urlRegex); - assert.equal(parsedContent, `test youtube`); + assert.equal(parsedContent, `test youtube`); done(); }); it('should turn relative links in post body to absolute urls', (done) => { const nconf = require('nconf'); - const content = 'test youtube some test '; + const content = 'test youtube some test '; let parsedContent = posts.relativeToAbsolute(content, posts.urlRegex); parsedContent = posts.relativeToAbsolute(parsedContent, posts.imgRegex); - assert.equal(parsedContent, `test youtube some test `); + assert.equal(parsedContent, `test youtube some test `); done(); }); });