From 8394d082ae1b6c2802dcb2a69fe615a4a01cc279 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Fri, 4 Jul 2014 13:40:55 -0400 Subject: [PATCH 1/2] fixes #1755 Fixed a bug where the trailing slash is not ignored when a query string is in use and the option stripTrailingSlash is enabled. --- lib/request.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/request.js b/lib/request.js index 9cbf313b9..177d8714d 100755 --- a/lib/request.js +++ b/lib/request.js @@ -162,18 +162,18 @@ Hoek.inherits(internals.Request, Events.EventEmitter); internals.Request.prototype._setUrl = function (url, stripTrailingSlash) { - if (stripTrailingSlash && - url.length > 1 && - url[url.length - 1] === '/') { - - url = url.slice(0, -1); - } - this.url = Url.parse(url, false); this.url.query = Qs.parse(this.url.query); // Override parsed value this.query = this.url.query; this.path = this.url.pathname || ''; // pathname excludes query + if (stripTrailingSlash && + this.path.length > 1 && + this.path[this.path.length - 1] === '/') { + + this.path = this.path.slice(0, -1); + } + if (this.path && this.path.indexOf('%') !== -1) { From 87c91524fbcf780072198b701f52968d2998e895 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 9 Jul 2014 18:05:21 -0500 Subject: [PATCH 2/2] fixes #1755 Added test for the condition where stripTrailingSlash failed if a query string was present. Test fails before the fix. Passes after the fix. --- test/request.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/request.js b/test/request.js index 030d8d172..1a182b386 100755 --- a/test/request.js +++ b/test/request.js @@ -842,6 +842,17 @@ describe('Request', function () { done(); }); }) + + it('does not strip trailing slash when a query string is present', function (done) { + + var server = new Hapi.Server({ router: { stripTrailingSlash: true } }); + server.route({ method: 'GET', path: '/test', handler: function (request, reply) { reply(); } }); + server.inject( '/test/?queryString1=test', function (res) { + + expect(res.statusCode).to.equal(200); + done(); + }); + }); }); describe('#log', { parallel: false }, function () {