Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix uri encoding of non-plain object string values

dates for example
  • Loading branch information...
commit ba8e7b9d3313f68f96c01a7d585ce62396fd3566 1 parent a172dcf
@tj authored
Showing with 8 additions and 2 deletions.
  1. +2 −2 lib/querystring.js
  2. +6 −0 test/stringify.js
View
4 lib/querystring.js
@@ -143,7 +143,7 @@ var stringify = exports.stringify = function(obj, prefix) {
} else if ('string' == typeof obj) {
return stringifyString(obj, prefix);
} else {
- return prefix + '=' + obj;
+ return prefix + '=' + encodeURIComponent(String(obj));
}
};
@@ -174,7 +174,7 @@ function stringifyArray(arr, prefix) {
var ret = [];
if (!prefix) throw new TypeError('stringify expects an object');
for (var i = 0; i < arr.length; i++) {
- ret.push(stringify(arr[i], prefix + '['+i+']'));
+ ret.push(stringify(arr[i], prefix + '[' + i + ']'));
}
return ret.join('&');
}
View
6 test/stringify.js
@@ -6,6 +6,8 @@ if (require.register) {
, expect = require('expect.js');
}
+var date = new Date(0);
+
var str_identities = {
'basics': [
{ str: 'foo=bar', obj: {'foo' : 'bar'}},
@@ -51,6 +53,9 @@ var str_identities = {
'numbers': [
{ str: 'limit[0]=1&limit[1]=2&limit[2]=3', obj: { limit: [1, 2, '3'] }},
{ str: 'limit=1', obj: { limit: 1 }}
+ ],
+ 'others': [
+ { str: 'at=' + encodeURIComponent(date), obj: { at: date } }
]
};
@@ -70,4 +75,5 @@ describe('qs.stringify()', function(){
it('should support escapes', test('escaping'))
it('should support nesting', test('nested'))
it('should support numbers', test('numbers'))
+ it('should support others', test('others'))
})
Please sign in to comment.
Something went wrong with that request. Please try again.