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.
This commit is contained in:
Aaron Heckmann 2015-05-21 12:28:03 -07:00
parent eb7277c95c
commit 6392ee0407
2 changed files with 7 additions and 2 deletions

View file

@ -131,8 +131,6 @@ module.exports = {
get query() { get query() {
var str = this.querystring; var str = this.querystring;
if (!str) return {};
var c = this._querycache = this._querycache || {}; var c = this._querycache = this._querycache || {};
return c[str] || (c[str] = qs.parse(str)); return c[str] || (c[str] = qs.parse(str));
}, },

View file

@ -7,6 +7,13 @@ describe('ctx.query', function(){
var ctx = context({ url: '/' }); var ctx = context({ url: '/' });
ctx.query.should.eql({}); 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(){ it('should return a parsed query-string', function(){