qs 6.1.1 → 6.1.3

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.
package/dist/qs.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Qs = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
1
+ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Qs = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2
2
  'use strict';
3
3
 
4
4
  var Stringify = require('./stringify');
@@ -25,9 +25,11 @@ var internals = {
25
25
  allowDots: false
26
26
  };
27
27
 
28
+ var has = Object.prototype.hasOwnProperty;
29
+
28
30
  internals.parseValues = function (str, options) {
29
31
  var obj = {};
30
- var parts = str.split(options.delimiter, options.parameterLimit === Infinity ? undefined : options.parameterLimit);
32
+ var parts = str.split(options.delimiter, options.parameterLimit === Infinity ? void undefined : options.parameterLimit);
31
33
 
32
34
  for (var i = 0; i < parts.length; ++i) {
33
35
  var part = parts[i];
@@ -43,7 +45,7 @@ internals.parseValues = function (str, options) {
43
45
  var key = Utils.decode(part.slice(0, pos));
44
46
  var val = Utils.decode(part.slice(pos + 1));
45
47
 
46
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
48
+ if (has.call(obj, key)) {
47
49
  obj[key] = [].concat(obj[key]).concat(val);
48
50
  } else {
49
51
  obj[key] = val;
@@ -96,26 +98,27 @@ internals.parseKeys = function (givenKey, val, options) {
96
98
 
97
99
  // The regex chunks
98
100
 
99
- var parent = /^([^[]*)/;
101
+ var brackets = /(\[[^[\]]*])/;
100
102
  var child = /(\[[^[\]]*])/g;
101
103
 
102
104
  // Get the parent
103
105
 
104
- var segment = parent.exec(key);
106
+ var segment = brackets.exec(key);
107
+ var parent = segment ? key.slice(0, segment.index) : key;
105
108
 
106
109
  // Stash the parent if it exists
107
110
 
108
111
  var keys = [];
109
- if (segment[1]) {
112
+ if (parent) {
110
113
  // If we aren't using plain objects, optionally prefix keys
111
114
  // that would overwrite object prototype properties
112
- if (!options.plainObjects && Object.prototype.hasOwnProperty(segment[1])) {
115
+ if (!options.plainObjects && has.call(Object.prototype, parent)) {
113
116
  if (!options.allowPrototypes) {
114
117
  return;
115
118
  }
116
119
  }
117
120
 
118
- keys.push(segment[1]);
121
+ keys[keys.length] = parent;
119
122
  }
120
123
 
121
124
  // Loop through children appending to the array until we hit depth
@@ -123,18 +126,18 @@ internals.parseKeys = function (givenKey, val, options) {
123
126
  var i = 0;
124
127
  while ((segment = child.exec(key)) !== null && i < options.depth) {
125
128
  i += 1;
126
- if (!options.plainObjects && Object.prototype.hasOwnProperty.call(Object.prototype, segment[1].slice(1, -1))) {
129
+ if (!options.plainObjects && has.call(Object.prototype, segment[1].slice(1, -1))) {
127
130
  if (!options.allowPrototypes) {
128
131
  return;
129
132
  }
130
133
  }
131
- keys.push(segment[1]);
134
+ keys[keys.length] = segment[1];
132
135
  }
133
136
 
134
137
  // If there's a remainder, just add whatever is left
135
138
 
136
139
  if (segment) {
137
- keys.push('[' + key.slice(segment.index) + ']');
140
+ keys[keys.length] = '[' + key.slice(segment.index + ']');
138
141
  }
139
142
 
140
143
  return internals.parseObject(keys, val, options);
@@ -320,6 +323,8 @@ var hexTable = (function () {
320
323
  return array;
321
324
  }());
322
325
 
326
+ var has = Object.prototype.hasOwnProperty;
327
+
323
328
  exports.arrayToObject = function (source, options) {
324
329
  var obj = options.plainObjects ? Object.create(null) : {};
325
330
  for (var i = 0; i < source.length; ++i) {
@@ -338,9 +343,11 @@ exports.merge = function (target, source, options) {
338
343
 
339
344
  if (typeof source !== 'object') {
340
345
  if (Array.isArray(target)) {
341
- target.push(source);
346
+ target[target.length] = source;
342
347
  } else if (typeof target === 'object') {
343
- target[source] = true;
348
+ if (options.plainObjects || options.allowPrototypes || !has.call(Object.prototype, source)) {
349
+ target[source] = true;
350
+ }
344
351
  } else {
345
352
  return [target, source];
346
353
  }
@@ -360,7 +367,7 @@ exports.merge = function (target, source, options) {
360
367
  return Object.keys(source).reduce(function (acc, key) {
361
368
  var value = source[key];
362
369
 
363
- if (Object.prototype.hasOwnProperty.call(acc, key)) {
370
+ if (has.call(acc, key)) {
364
371
  acc[key] = exports.merge(acc[key], value, options);
365
372
  } else {
366
373
  acc[key] = value;
@@ -437,14 +444,14 @@ exports.compact = function (obj, references) {
437
444
  return refs[lookup];
438
445
  }
439
446
 
440
- refs.push(obj);
447
+ refs[refs.length] = obj;
441
448
 
442
449
  if (Array.isArray(obj)) {
443
450
  var compacted = [];
444
451
 
445
452
  for (var i = 0; i < obj.length; ++i) {
446
453
  if (typeof obj[i] !== 'undefined') {
447
- compacted.push(obj[i]);
454
+ compacted[compacted.length] = obj[i];
448
455
  }
449
456
  }
450
457
 
@@ -473,4 +480,4 @@ exports.isBuffer = function (obj) {
473
480
  };
474
481
 
475
482
  },{}]},{},[1])(1)
476
- });
483
+ });
package/lib/index.js CHANGED
File without changes
package/lib/parse.js CHANGED
@@ -13,9 +13,11 @@ var internals = {
13
13
  allowDots: false
14
14
  };
15
15
 
16
+ var has = Object.prototype.hasOwnProperty;
17
+
16
18
  internals.parseValues = function (str, options) {
17
19
  var obj = {};
18
- var parts = str.split(options.delimiter, options.parameterLimit === Infinity ? undefined : options.parameterLimit);
20
+ var parts = str.split(options.delimiter, options.parameterLimit === Infinity ? void undefined : options.parameterLimit);
19
21
 
20
22
  for (var i = 0; i < parts.length; ++i) {
21
23
  var part = parts[i];
@@ -31,7 +33,7 @@ internals.parseValues = function (str, options) {
31
33
  var key = Utils.decode(part.slice(0, pos));
32
34
  var val = Utils.decode(part.slice(pos + 1));
33
35
 
34
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
36
+ if (has.call(obj, key)) {
35
37
  obj[key] = [].concat(obj[key]).concat(val);
36
38
  } else {
37
39
  obj[key] = val;
@@ -84,26 +86,27 @@ internals.parseKeys = function (givenKey, val, options) {
84
86
 
85
87
  // The regex chunks
86
88
 
87
- var parent = /^([^[]*)/;
89
+ var brackets = /(\[[^[\]]*])/;
88
90
  var child = /(\[[^[\]]*])/g;
89
91
 
90
92
  // Get the parent
91
93
 
92
- var segment = parent.exec(key);
94
+ var segment = brackets.exec(key);
95
+ var parent = segment ? key.slice(0, segment.index) : key;
93
96
 
94
97
  // Stash the parent if it exists
95
98
 
96
99
  var keys = [];
97
- if (segment[1]) {
100
+ if (parent) {
98
101
  // If we aren't using plain objects, optionally prefix keys
99
102
  // that would overwrite object prototype properties
100
- if (!options.plainObjects && Object.prototype.hasOwnProperty(segment[1])) {
103
+ if (!options.plainObjects && has.call(Object.prototype, parent)) {
101
104
  if (!options.allowPrototypes) {
102
105
  return;
103
106
  }
104
107
  }
105
108
 
106
- keys.push(segment[1]);
109
+ keys[keys.length] = parent;
107
110
  }
108
111
 
109
112
  // Loop through children appending to the array until we hit depth
@@ -111,18 +114,18 @@ internals.parseKeys = function (givenKey, val, options) {
111
114
  var i = 0;
112
115
  while ((segment = child.exec(key)) !== null && i < options.depth) {
113
116
  i += 1;
114
- if (!options.plainObjects && Object.prototype.hasOwnProperty.call(Object.prototype, segment[1].slice(1, -1))) {
117
+ if (!options.plainObjects && has.call(Object.prototype, segment[1].slice(1, -1))) {
115
118
  if (!options.allowPrototypes) {
116
119
  return;
117
120
  }
118
121
  }
119
- keys.push(segment[1]);
122
+ keys[keys.length] = segment[1];
120
123
  }
121
124
 
122
125
  // If there's a remainder, just add whatever is left
123
126
 
124
127
  if (segment) {
125
- keys.push('[' + key.slice(segment.index) + ']');
128
+ keys[keys.length] = '[' + key.slice(segment.index + ']');
126
129
  }
127
130
 
128
131
  return internals.parseObject(keys, val, options);
package/lib/stringify.js CHANGED
File without changes
package/lib/utils.js CHANGED
@@ -9,6 +9,8 @@ var hexTable = (function () {
9
9
  return array;
10
10
  }());
11
11
 
12
+ var has = Object.prototype.hasOwnProperty;
13
+
12
14
  exports.arrayToObject = function (source, options) {
13
15
  var obj = options.plainObjects ? Object.create(null) : {};
14
16
  for (var i = 0; i < source.length; ++i) {
@@ -27,9 +29,11 @@ exports.merge = function (target, source, options) {
27
29
 
28
30
  if (typeof source !== 'object') {
29
31
  if (Array.isArray(target)) {
30
- target.push(source);
32
+ target[target.length] = source;
31
33
  } else if (typeof target === 'object') {
32
- target[source] = true;
34
+ if (options.plainObjects || options.allowPrototypes || !has.call(Object.prototype, source)) {
35
+ target[source] = true;
36
+ }
33
37
  } else {
34
38
  return [target, source];
35
39
  }
@@ -49,7 +53,7 @@ exports.merge = function (target, source, options) {
49
53
  return Object.keys(source).reduce(function (acc, key) {
50
54
  var value = source[key];
51
55
 
52
- if (Object.prototype.hasOwnProperty.call(acc, key)) {
56
+ if (has.call(acc, key)) {
53
57
  acc[key] = exports.merge(acc[key], value, options);
54
58
  } else {
55
59
  acc[key] = value;
@@ -126,14 +130,14 @@ exports.compact = function (obj, references) {
126
130
  return refs[lookup];
127
131
  }
128
132
 
129
- refs.push(obj);
133
+ refs[refs.length] = obj;
130
134
 
131
135
  if (Array.isArray(obj)) {
132
136
  var compacted = [];
133
137
 
134
138
  for (var i = 0; i < obj.length; ++i) {
135
139
  if (typeof obj[i] !== 'undefined') {
136
- compacted.push(obj[i]);
140
+ compacted[compacted.length] = obj[i];
137
141
  }
138
142
  }
139
143
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "qs",
3
3
  "description": "A querystring parser that supports nesting and arrays, with a depth limit",
4
4
  "homepage": "https://github.com/ljharb/qs",
5
- "version": "6.1.1",
5
+ "version": "6.1.3",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/ljharb/qs.git"
@@ -34,7 +34,8 @@
34
34
  "evalmd": "^0.0.16"
35
35
  },
36
36
  "scripts": {
37
- "test": "parallelshell 'npm run readme' 'npm run lint' 'npm run coverage'",
37
+ "pretest": "npm run lint && npm run readme",
38
+ "test": "npm run coverage",
38
39
  "tests-only": "node test",
39
40
  "readme": "evalmd README.md",
40
41
  "lint": "eslint lib/*.js text/*.js",
package/test/parse.js CHANGED
@@ -142,8 +142,6 @@ test('parse()', function (t) {
142
142
  st.end();
143
143
  });
144
144
 
145
- t.deepEqual(qs.parse('a[b]=c&a=d'), { a: { b: 'c', d: true } }, 'can add keys to objects');
146
-
147
145
  t.test('correctly prunes undefined values when converting an array to an object', function (st) {
148
146
  st.deepEqual(qs.parse('a[2]=b&a[99999999]=c'), { a: { '2': 'b', '99999999': 'c' } });
149
147
  st.end();
@@ -401,10 +399,47 @@ test('parse()', function (t) {
401
399
 
402
400
  t.test('params starting with a closing bracket', function (st) {
403
401
  st.deepEqual(qs.parse(']=toString'), { ']': 'toString' });
402
+ st.deepEqual(qs.parse(']]=toString'), { ']]': 'toString' });
403
+ st.deepEqual(qs.parse(']hello]=toString'), { ']hello]': 'toString' });
404
+ st.end();
405
+ });
406
+
407
+ t.test('params starting with a starting bracket', function (st) {
408
+ st.deepEqual(qs.parse('[=toString'), { '[': 'toString' });
409
+ st.deepEqual(qs.parse('[[=toString'), { '[[': 'toString' });
410
+ st.deepEqual(qs.parse('[hello[=toString'), { '[hello[': 'toString' });
411
+ st.end();
412
+ });
413
+
414
+ t.test('add keys to objects', function (st) {
415
+ st.deepEqual(
416
+ qs.parse('a[b]=c&a=d'),
417
+ { a: { b: 'c', d: true } },
418
+ 'can add keys to objects'
419
+ );
420
+
421
+ st.deepEqual(
422
+ qs.parse('a[b]=c&a=toString'),
423
+ { a: { b: 'c' } },
424
+ 'can not overwrite prototype'
425
+ );
426
+
427
+ st.deepEqual(
428
+ qs.parse('a[b]=c&a=toString', { allowPrototypes: true }),
429
+ { a: { b: 'c', toString: true } },
430
+ 'can overwrite prototype with allowPrototypes true'
431
+ );
432
+
433
+ st.deepEqual(
434
+ qs.parse('a[b]=c&a=toString', { plainObjects: true }),
435
+ { a: { b: 'c', toString: true } },
436
+ 'can overwrite prototype with plainObjects true'
437
+ );
438
+
404
439
  st.end();
405
440
  });
406
441
 
407
- t.test('can return plain objects', function (st) {
442
+ t.test('can return null objects', { skip: !Object.create }, function (st) {
408
443
  var expected = Object.create(null);
409
444
  expected.a = Object.create(null);
410
445
  expected.a.b = 'c';
package/test/stringify.js CHANGED
File without changes
package/test/utils.js CHANGED
File without changes
package/.npmignore DELETED
@@ -1,18 +0,0 @@
1
- .idea
2
- *.iml
3
- npm-debug.log
4
- dump.rdb
5
- node_modules
6
- results.tap
7
- results.xml
8
- npm-shrinkwrap.json
9
- config.json
10
- .DS_Store
11
- */.DS_Store
12
- */*/.DS_Store
13
- ._*
14
- */._*
15
- */*/._*
16
- coverage.*
17
- lib-cov
18
- complexity.md