From 42218cbfe7e77bbcd0326db15363dc281c95c56a Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Tue, 24 Jan 2012 19:10:43 -0800 Subject: [PATCH] Fixed: port existing query-string fix (browser). Closes #57 --- lib/superagent.js | 5 ++++- test/test.request.js | 12 +++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/superagent.js b/lib/superagent.js index 68fe749ad..fa0f4d98d 100644 --- a/lib/superagent.js +++ b/lib/superagent.js @@ -554,7 +554,10 @@ var superagent = function(exports){ // querystring if ('GET' == this.method && data) { - this.url += '?' + exports.serializeObject(data); + data = exports.serializeObject(data); + this.url += ~this.url.indexOf('?') + ? '&' + data + : '?' + data; data = null; } diff --git a/test/test.request.js b/test/test.request.js index e50bdbe1d..a4cba5ae2 100644 --- a/test/test.request.js +++ b/test/test.request.js @@ -358,6 +358,16 @@ test('GET querystring object', function(next){ }); }); +test('GET querystring append original', function(next){ + request + .get('/querystring?search=Manny') + .send({ range: '1..5' }) + .end(function(res){ + assert.eql(res.body, { search: 'Manny', range: '1..5' }); + next(); + }); +}); + test('GET querystring multiple objects', function(next){ request .get('/querystring') @@ -372,7 +382,7 @@ test('GET querystring multiple objects', function(next){ test('GET querystring object .get(uri, obj)', function(next){ request - .get('/querystring', { search: 'Manny'}) + .get('/querystring', { search: 'Manny' }) .end(function(res){ assert.eql(res.body, { search: 'Manny' }); next();