0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

🐛 Fixed doubled query params for url/admin-url redirection

no issue

- express adds the query parameters to the `originalUrl`
- we have to ensure that we don't add the query params twice
This commit is contained in:
kirrg001 2017-09-13 19:30:13 +02:00 committed by Aileen Nowak
parent 79959d9581
commit 18abb425fc
2 changed files with 23 additions and 1 deletions

View file

@ -95,7 +95,7 @@ urlRedirects = function urlRedirects(req, res, next) {
var redirectFn = res.isAdmin ? _private.getAdminRedirectUrl : _private.getBlogRedirectUrl,
redirectUrl = redirectFn({
requestedHost: req.get('host'),
requestedUrl: req.originalUrl || req.url,
requestedUrl: url.parse(req.originalUrl || req.url).pathname,
queryParameters: req.query,
secure: req.secure
});

View file

@ -244,6 +244,28 @@ describe('UNIT: url redirects', function () {
done();
});
it('[redirect] original url has search params', function (done) {
configUtils.set({
url: 'http://default.com:2368',
admin: {
url: 'https://admin.default.com:2368'
}
});
host = 'default.com:2368';
res.isAdmin = true;
req.originalUrl = '/ghost/something?a=b';
req.query = {
a: 'b'
};
urlRedirects(req, res, next);
next.called.should.be.false();
res.redirect.calledWith(301, 'https://admin.default.com:2368/ghost/something/?a=b').should.be.true();
done();
});
it('[redirect] same url and admin url, but different protocol.', function (done) {
configUtils.set({
url: 'http://default.com:2368',