From acb30463e381218ce5108756810b16253946b1e4 Mon Sep 17 00:00:00 2001 From: Lauri Svan Date: Wed, 6 Jul 2016 07:42:06 +0300 Subject: [PATCH] Fix: Query strings fails for falsifying booleans and numbers --- package.json | 2 +- src/Request.js | 2 +- test/RequestSpec.js | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 10b14fb..7d495f5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "request-promise-lite", - "version": "0.5.1", + "version": "0.5.2", "description": "Lightweight, promiseful http/https request client", "main": "lib/index.js", "repository": { diff --git a/src/Request.js b/src/Request.js index 1fb05ce..a6a6736 100644 --- a/src/Request.js +++ b/src/Request.js @@ -38,7 +38,7 @@ export default class Request { const unparsedValues = map[key]; let values; - if (!unparsedValues) { + if (typeof unparsedValues === 'undefined') { // TODO Check this - can we send keys that have values? request module thinks 'no' //return key; return ''; diff --git a/test/RequestSpec.js b/test/RequestSpec.js index 309c521..36be690 100644 --- a/test/RequestSpec.js +++ b/test/RequestSpec.js @@ -53,6 +53,23 @@ describe('Request - test against httpbin.org', () => { }); }); + it('Supports booleans, strings, and numbers in query object', () => { + url = 'https://httpbin.org/get'; + const qs = { + text: 'test text', + number: -1, + boolean: false, + }; + request = new Request('GET', url, { json: true, qs: qs }); + + return request.run() + .then(response => { + expect(response.args.text).to.equal('test text'); + expect(response.args.number).to.equal('-1'); + expect(response.args.boolean).to.equal('false'); + }); + }); + it('Accepts custom headers', () => { url = 'https://httpbin.org/headers'; headers = {