From a89f5c21562fe75b083a270090eadfbe318e5954 Mon Sep 17 00:00:00 2001 From: Jeremiah Senkpiel Date: Thu, 19 Mar 2015 18:51:55 -0400 Subject: [PATCH] querystring: parse numbers correctly Fixes a number parsing regression introduced in 85a92a3 Fixes: https://github.com/iojs/io.js/issues/1208 PR-URL: https://github.com/iojs/io.js/pull/1213 Reviewed-By: Rod Vagg Reviewed-By: Brian White --- lib/querystring.js | 3 +++ test/parallel/test-querystring.js | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/querystring.js b/lib/querystring.js index af320cf8f86397..f0d473a39ae24d 100644 --- a/lib/querystring.js +++ b/lib/querystring.js @@ -90,6 +90,9 @@ var hexTable = new Array(256); for (var i = 0; i < 256; ++i) hexTable[i] = '%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase(); QueryString.escape = function(str) { + // replaces encodeURIComponent + // http://www.ecma-international.org/ecma-262/5.1/#sec-15.1.3.4 + str = '' + str; var len = str.length; var out = ''; var i, c; diff --git a/test/parallel/test-querystring.js b/test/parallel/test-querystring.js index e2591d709015f5..17fa6df9247747 100644 --- a/test/parallel/test-querystring.js +++ b/test/parallel/test-querystring.js @@ -138,6 +138,14 @@ qsWeirdObjects.forEach(function(testCase) { assert.equal(testCase[1], qs.stringify(testCase[0])); }); +// coerce numbers to string +assert.strictEqual('foo=0', qs.stringify({ foo: 0 })); +assert.strictEqual('foo=0', qs.stringify({ foo: -0 })); +assert.strictEqual('foo=3', qs.stringify({ foo: 3 })); +assert.strictEqual('foo=-72.42', qs.stringify({ foo: -72.42 })); +assert.strictEqual('foo=', qs.stringify({ foo: NaN })); +assert.strictEqual('foo=', qs.stringify({ foo: Infinity })); + // nested var f = qs.stringify({ a: 'b',