From 377883db9825c4d6b9b29f968761fa6843efb87f Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Sun, 28 Feb 2021 04:34:43 +0100 Subject: [PATCH] fix pads with spaces (#4884) --- src/node/hooks/express/padurlsanitize.js | 2 +- src/tests/backend/specs/pads-with-spaces.js | 24 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/tests/backend/specs/pads-with-spaces.js diff --git a/src/node/hooks/express/padurlsanitize.js b/src/node/hooks/express/padurlsanitize.js index 30297479..b805fc4b 100644 --- a/src/node/hooks/express/padurlsanitize.js +++ b/src/node/hooks/express/padurlsanitize.js @@ -18,7 +18,7 @@ exports.expressCreateServer = (hookName, args, cb) => { next(); } else { // the pad id was sanitized, so we redirect to the sanitized version - const realURL = encodeURIComponent(sanitizedPadId) + new URL(req.url).search; + const realURL = encodeURIComponent(sanitizedPadId) + new URL(req.url, 'http://invalid.invalid').search; res.header('Location', realURL); res.status(302).send(`You should be redirected to ${realURL}`); } diff --git a/src/tests/backend/specs/pads-with-spaces.js b/src/tests/backend/specs/pads-with-spaces.js new file mode 100644 index 00000000..0db99865 --- /dev/null +++ b/src/tests/backend/specs/pads-with-spaces.js @@ -0,0 +1,24 @@ +'use strict'; + +const common = require('../common'); +const assert = require('../assert-legacy').strict; + +let agent; + +describe(__filename, function () { + before(async function () { + agent = await common.init(); + }); + + it('supports pads with spaces, regression test for #4883', async function () { + await agent.get('/p/pads with spaces') + .expect(302) + .expect('location', 'pads_with_spaces'); + }); + + it('supports pads with spaces and query, regression test for #4883', async function () { + await agent.get('/p/pads with spaces?showChat=true&noColors=false') + .expect(302) + .expect('location', 'pads_with_spaces?showChat=true&noColors=false'); + }); +});