qs 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ Please view our [hapijs contributing guide](https://github.com/hapijs/hapi/blob/master/CONTRIBUTING.md).
package/lib/parse.js CHANGED
@@ -153,5 +153,3 @@ module.exports = function (str, depth, delimiter) {
153
153
 
154
154
  return Utils.compact(obj);
155
155
  };
156
-
157
-
package/lib/utils.js CHANGED
@@ -106,7 +106,7 @@ exports.decode = function (str) {
106
106
 
107
107
  exports.compact = function (obj) {
108
108
 
109
- if (typeof obj !== 'object') {
109
+ if (typeof obj !== 'object' || obj === null) {
110
110
  return obj;
111
111
  }
112
112
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qs",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "A querystring parser that supports nesting and arrays, with a depth limit",
5
5
  "homepage": "https://github.com/hapijs/qs",
6
6
  "main": "index.js",
package/test/parse.js CHANGED
@@ -192,7 +192,7 @@ describe('#parse', function () {
192
192
  done();
193
193
  });
194
194
 
195
- it('should compact sparse arrays', function (done) {
195
+ it('compacts sparse arrays', function (done) {
196
196
 
197
197
  expect(Qs.parse('a[10]=1&a[2]=2')).to.deep.equal({ a: ['2', '1'] });
198
198
  done();
@@ -253,9 +253,49 @@ describe('#parse', function () {
253
253
  done();
254
254
  });
255
255
 
256
- it('should not use non-string objects as delimiters', function (done) {
256
+ it('does not use non-string objects as delimiters', function (done) {
257
257
 
258
258
  expect(Qs.parse('a=b&c=d', {})).to.deep.equal({ a: 'b', c: 'd' });
259
259
  done();
260
260
  });
261
+
262
+ it('parses an object', function (done) {
263
+
264
+ var input = {
265
+ "user[name]": {"pop[bob]": 3},
266
+ "user[email]": null
267
+ };
268
+
269
+ var expected = {
270
+ "user": {
271
+ "name": {"pop[bob]": 3},
272
+ "email": null
273
+ }
274
+ };
275
+
276
+ var result = Qs.parse(input);
277
+
278
+ expect(result).to.deep.equal(expected);
279
+ done();
280
+ });
281
+
282
+ it('parses an object and not child values', function (done) {
283
+
284
+ var input = {
285
+ "user[name]": {"pop[bob]": { "test": 3 }},
286
+ "user[email]": null
287
+ };
288
+
289
+ var expected = {
290
+ "user": {
291
+ "name": {"pop[bob]": { "test": 3 }},
292
+ "email": null
293
+ }
294
+ };
295
+
296
+ var result = Qs.parse(input);
297
+
298
+ expect(result).to.deep.equal(expected);
299
+ done();
300
+ });
261
301
  });