Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed stringify()ing numbers. Closes #23

  • Loading branch information...
commit 37416fcacbfb9c6688571715b7f76464a043af1b 1 parent 3059db3
TJ Holowaychuk authored
Showing with 11 additions and 1 deletion.
  1. +3 −1 lib/querystring.js
  2. +8 −0 test/stringify.js
4 lib/querystring.js
View
@@ -161,7 +161,7 @@ var stringify = exports.stringify = function(obj, prefix) {
} else if ('string' == typeof obj) {
return stringifyString(obj, prefix);
} else {
- return prefix;
+ return prefix + '=' + obj;
}
};
@@ -210,12 +210,14 @@ function stringifyObject(obj, prefix) {
var ret = []
, keys = Object.keys(obj)
, key;
+
for (var i = 0, len = keys.length; i < len; ++i) {
key = keys[i];
ret.push(stringify(obj[key], prefix
? prefix + '[' + encodeURIComponent(key) + ']'
: encodeURIComponent(key)));
}
+
return ret.join('&');
}
8 test/stringify.js
View
@@ -46,6 +46,10 @@ var qs = require('../')
'errors': [
{ parsed: 'foo=bar', message: 'stringify expects an object' },
{ parsed: ['foo', 'bar'], message: 'stringify expects an object' }
+ ],
+ 'numbers': [
+ { query_string: 'limit[]=1&limit[]=2&limit[]=3', parsed: { limit: [1, 2, '3'] }},
+ { query_string: 'limit=1', parsed: { limit: 1 }}
]
};
@@ -83,6 +87,10 @@ module.exports = {
'test nested': function() {
test('nested');
},
+
+ 'test numbers': function(){
+ test('numbers');
+ },
'test errors': function() {
var parsed, message;
Please sign in to comment.
Something went wrong with that request. Please try again.