From 006f93533f758cbc1343be746f67ec96e0254b39 Mon Sep 17 00:00:00 2001 From: Matt Travi Date: Tue, 6 Dec 2016 13:26:21 -0600 Subject: [PATCH] referenced the raw request when setting next resolves #150 --- lib/index.js | 2 +- test/index.js | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 22a395c..abe58e2 100755 --- a/lib/index.js +++ b/lib/index.js @@ -210,7 +210,7 @@ internals.implementation = function (server, options) { uri += '?'; } - uri += settings.appendNext + '=' + encodeURIComponent(request.url.path); + uri += settings.appendNext + '=' + encodeURIComponent(request.raw.req.url); } return reply('You are being redirected...', null, result).redirect(uri); diff --git a/test/index.js b/test/index.js index 1a96dbc..92f0a1f 100755 --- a/test/index.js +++ b/test/index.js @@ -1569,6 +1569,45 @@ describe('scheme', () => { }); }); + it('retains the original path when onRequest re-routes', (done) => { + + const server = new Hapi.Server(); + server.connection(); + server.register(require('../'), (err) => { + + expect(err).to.not.exist(); + + server.auth.strategy('default', 'cookie', true, { + password: 'password-should-be-32-characters', + ttl: 60 * 1000, + redirectTo: 'http://example.com/login?mode=1', + appendNext: true + }); + + server.route({ + method: 'GET', path: '/', handler: function (request, reply) { + + return reply('never'); + } + }); + + server.ext('onRequest', (request, reply) => { + + request.setUrl('/'); + + reply.continue(); + }); + + server.inject('/foo?bar=baz', (res) => { + + expect(res.statusCode).to.equal(302); + expect(res.headers.location).to.equal('http://example.com/login?mode=1&next=%2Ffoo%3Fbar%3Dbaz'); + done(); + }); + }); + }); + + it('appends the custom query when appendNext is string', (done) => { const server = new Hapi.Server();