From 9e2c4bf7815824cf14f72c61b50f2bc9b062fd76 Mon Sep 17 00:00:00 2001 From: SamTV12345 <40429738+SamTV12345@users.noreply.github.com> Date: Sat, 20 Jan 2024 23:11:52 +0100 Subject: [PATCH] Fixed favicon not being loaded from url. (#6113) * Fixed favicon not being loaded from url. * Fixed tests. --- src/node/hooks/express/specialpages.js | 10 ++++++++++ src/tests/backend/specs/favicon.js | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/src/node/hooks/express/specialpages.js b/src/node/hooks/express/specialpages.js index 4f41d8cd0..18a17988a 100644 --- a/src/node/hooks/express/specialpages.js +++ b/src/node/hooks/express/specialpages.js @@ -43,6 +43,16 @@ exports.expressPreSession = async (hookName, {app}) => { app.get('/favicon.ico', (req, res, next) => { (async () => { + /* + If this is a url we simply redirect to that one. + */ + if (settings.favicon && settings.favicon.startsWith('http')) { + res.redirect(settings.favicon); + res.send(); + return; + } + + const fns = [ ...(settings.favicon ? [path.resolve(settings.root, settings.favicon)] : []), path.join(settings.root, 'src', 'static', 'skins', settings.skinName, 'favicon.ico'), diff --git a/src/tests/backend/specs/favicon.js b/src/tests/backend/specs/favicon.js index a5e3095de..98c308061 100644 --- a/src/tests/backend/specs/favicon.js +++ b/src/tests/backend/specs/favicon.js @@ -51,6 +51,12 @@ describe(__filename, function () { assert(gotIcon.equals(wantCustomIcon)); }); + it('uses custom favicon from url', async function () { + settings.favicon = 'https://etherpad.org/favicon.ico'; + await agent.get('/favicon.ico') + .expect(302); + }); + it('uses custom favicon if set (absolute pathname)', async function () { settings.favicon = path.join(__dirname, 'favicon-test-custom.png'); assert(path.isAbsolute(settings.favicon));