From 227d9985426214b6ac68702933346000298d7790 Mon Sep 17 00:00:00 2001 From: Jason LeBrun Date: Thu, 18 Apr 2013 15:21:29 -0700 Subject: [PATCH] Update the internal path variable when querystring is changed If the querystring is changed *after* creating a request object, update the internal path to ensure that the proper request is sent over the wire. --- index.js | 1 + tests/test-qs.js | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/index.js b/index.js index cdd313808..6c1668740 100755 --- a/index.js +++ b/index.js @@ -930,6 +930,7 @@ Request.prototype.qs = function (q, clobber) { this.uri = url.parse(this.uri.href.split('?')[0] + '?' + qs.stringify(base)) this.url = this.uri + this.path = this.uri.path return this } diff --git a/tests/test-qs.js b/tests/test-qs.js index f81a8df90..65958e6a3 100644 --- a/tests/test-qs.js +++ b/tests/test-qs.js @@ -32,3 +32,11 @@ var req5 = request.get({ uri: 'http://www.google.com', qs: {}}) setTimeout(function(){ assert.equal('/', req5.path) }, 1) + + +// Test modifying the qs after creating the request +var req6 = request.get({ uri: 'http://www.google.com', qs: {}}); +req6.qs({ q: "test" }); +process.nextTick(function() { + assert.equal('/?q=test', req6.path); +});