From 6392ee0407a99bb128edc2edb5cf60fcc1b1d8d5 Mon Sep 17 00:00:00 2001 From: Aaron Heckmann Date: Thu, 21 May 2015 12:28:03 -0700 Subject: [PATCH] return same object from request.query Before this change, calling request.query when there was no querystring resulted in a new object created and returned each time. If the resulting object was ever changed, accessing request.query would not reflect it and cause weird bugs. --- lib/request.js | 2 -- test/request/query.js | 7 +++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/request.js b/lib/request.js index f8d75e4..cb7dcda 100644 --- a/lib/request.js +++ b/lib/request.js @@ -131,8 +131,6 @@ module.exports = { get query() { var str = this.querystring; - if (!str) return {}; - var c = this._querycache = this._querycache || {}; return c[str] || (c[str] = qs.parse(str)); }, diff --git a/test/request/query.js b/test/request/query.js index b6669be..99a74ee 100644 --- a/test/request/query.js +++ b/test/request/query.js @@ -7,6 +7,13 @@ describe('ctx.query', function(){ var ctx = context({ url: '/' }); ctx.query.should.eql({}); }) + + it('should return the same object each time it\'s accessed', function(done) { + var ctx = context({ url: '/' }); + ctx.query.a = '2'; + ctx.query.a.should.equal('2'); + done(); + }); }) it('should return a parsed query-string', function(){