Permalink
Browse files

output key= for null or undefined values. Closes #52

  • Loading branch information...
1 parent a1f32de commit 0518c7d1fa129abfcb02a6439e0e0e72e94035de @tj committed Mar 20, 2013
Showing with 8 additions and 5 deletions.
  1. +7 −4 index.js
  2. +1 −1 test/stringify.js
View
@@ -195,10 +195,13 @@ function stringifyObject(obj, prefix) {
for (var i = 0, len = keys.length; i < len; ++i) {
key = keys[i];
- if (null == obj[key]) continue;
- ret.push(stringify(obj[key], prefix
- ? prefix + '[' + encodeURIComponent(key) + ']'
- : encodeURIComponent(key)));
+ if (null == obj[key]) {
+ ret.push(encodeURIComponent(key) + '=');
+ } else {
+ ret.push(stringify(obj[key], prefix
+ ? prefix + '[' + encodeURIComponent(key) + ']'
+ : encodeURIComponent(key)));
+ }
}
return ret.join('&');
View
@@ -17,7 +17,7 @@ var str_identities = {
{ str: 'my%20weird%20field=q1!2%22\'w%245%267%2Fz8)%3F', obj: {'my weird field': "q1!2\"'w$5&7/z8)?"}},
{ str: 'foo%3Dbaz=bar', obj: {'foo=baz': 'bar'}},
{ str: 'foo=bar&bar=baz', obj: {foo: 'bar', bar: 'baz'}},
- { str: 'foo=bar', obj: { foo: 'bar', baz: null, raz: undefined }}
+ { str: 'foo=bar&baz=&raz=', obj: { foo: 'bar', baz: null, raz: undefined }}
],
'escaping': [
{ str: 'foo=foo%20bar', obj: {foo: 'foo bar'}},

0 comments on commit 0518c7d

Please sign in to comment.