Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 0518c7d1fa129abfcb02a6439e0e0e72e94035de 1 parent a1f32de
@tj authored
Showing with 8 additions and 5 deletions.
  1. +7 −4 index.js
  2. +1 −1  test/stringify.js
View
11 index.js
@@ -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
2  test/stringify.js
@@ -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'}},
Please sign in to comment.
Something went wrong with that request. Please try again.