Pushing changes
This commit is contained in:
1
node_modules/qs/.jshintignore
generated
vendored
Normal file
1
node_modules/qs/.jshintignore
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
node_modules
|
10
node_modules/qs/.jshintrc
generated
vendored
Normal file
10
node_modules/qs/.jshintrc
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"node": true,
|
||||
|
||||
"curly": true,
|
||||
"latedef": true,
|
||||
"quotmark": true,
|
||||
"undef": true,
|
||||
"unused": true,
|
||||
"trailing": true
|
||||
}
|
18
node_modules/qs/.npmignore
generated
vendored
Normal file
18
node_modules/qs/.npmignore
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
.idea
|
||||
*.iml
|
||||
npm-debug.log
|
||||
dump.rdb
|
||||
node_modules
|
||||
results.tap
|
||||
results.xml
|
||||
npm-shrinkwrap.json
|
||||
config.json
|
||||
.DS_Store
|
||||
*/.DS_Store
|
||||
*/*/.DS_Store
|
||||
._*
|
||||
*/._*
|
||||
*/*/._*
|
||||
coverage.*
|
||||
lib-cov
|
||||
complexity.md
|
4
node_modules/qs/.travis.yml
generated
vendored
Normal file
4
node_modules/qs/.travis.yml
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
language: node_js
|
||||
|
||||
node_js:
|
||||
- 0.10
|
68
node_modules/qs/CHANGELOG.md
generated
vendored
Normal file
68
node_modules/qs/CHANGELOG.md
generated
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
|
||||
## [**2.3.3**](https://github.com/hapijs/qs/issues?milestone=18&state=open)
|
||||
- [**#59**](https://github.com/hapijs/qs/issues/59) make sure array indexes are >= 0, closes #57
|
||||
- [**#58**](https://github.com/hapijs/qs/issues/58) make qs usable for browser loader
|
||||
|
||||
## [**2.3.2**](https://github.com/hapijs/qs/issues?milestone=17&state=closed)
|
||||
- [**#55**](https://github.com/hapijs/qs/issues/55) allow merging a string into an object
|
||||
|
||||
## [**2.3.1**](https://github.com/hapijs/qs/issues?milestone=16&state=closed)
|
||||
- [**#52**](https://github.com/hapijs/qs/issues/52) Return "undefined" and "false" instead of throwing "TypeError".
|
||||
|
||||
## [**2.3.0**](https://github.com/hapijs/qs/issues?milestone=15&state=closed)
|
||||
- [**#50**](https://github.com/hapijs/qs/issues/50) add option to omit array indices, closes #46
|
||||
|
||||
## [**2.2.5**](https://github.com/hapijs/qs/issues?milestone=14&state=closed)
|
||||
- [**#39**](https://github.com/hapijs/qs/issues/39) Is there an alternative to Buffer.isBuffer?
|
||||
- [**#49**](https://github.com/hapijs/qs/issues/49) refactor utils.merge, fixes #45
|
||||
- [**#41**](https://github.com/hapijs/qs/issues/41) avoid browserifying Buffer, for #39
|
||||
|
||||
## [**2.2.4**](https://github.com/hapijs/qs/issues?milestone=13&state=closed)
|
||||
- [**#38**](https://github.com/hapijs/qs/issues/38) how to handle object keys beginning with a number
|
||||
|
||||
## [**2.2.3**](https://github.com/hapijs/qs/issues?milestone=12&state=closed)
|
||||
- [**#37**](https://github.com/hapijs/qs/issues/37) parser discards first empty value in array
|
||||
- [**#36**](https://github.com/hapijs/qs/issues/36) Update to lab 4.x
|
||||
|
||||
## [**2.2.2**](https://github.com/hapijs/qs/issues?milestone=11&state=closed)
|
||||
- [**#33**](https://github.com/hapijs/qs/issues/33) Error when plain object in a value
|
||||
- [**#34**](https://github.com/hapijs/qs/issues/34) use Object.prototype.hasOwnProperty.call instead of obj.hasOwnProperty
|
||||
- [**#24**](https://github.com/hapijs/qs/issues/24) Changelog? Semver?
|
||||
|
||||
## [**2.2.1**](https://github.com/hapijs/qs/issues?milestone=10&state=closed)
|
||||
- [**#32**](https://github.com/hapijs/qs/issues/32) account for circular references properly, closes #31
|
||||
- [**#31**](https://github.com/hapijs/qs/issues/31) qs.parse stackoverflow on circular objects
|
||||
|
||||
## [**2.2.0**](https://github.com/hapijs/qs/issues?milestone=9&state=closed)
|
||||
- [**#26**](https://github.com/hapijs/qs/issues/26) Don't use Buffer global if it's not present
|
||||
- [**#30**](https://github.com/hapijs/qs/issues/30) Bug when merging non-object values into arrays
|
||||
- [**#29**](https://github.com/hapijs/qs/issues/29) Don't call Utils.clone at the top of Utils.merge
|
||||
- [**#23**](https://github.com/hapijs/qs/issues/23) Ability to not limit parameters?
|
||||
|
||||
## [**2.1.0**](https://github.com/hapijs/qs/issues?milestone=8&state=closed)
|
||||
- [**#22**](https://github.com/hapijs/qs/issues/22) Enable using a RegExp as delimiter
|
||||
|
||||
## [**2.0.0**](https://github.com/hapijs/qs/issues?milestone=7&state=closed)
|
||||
- [**#18**](https://github.com/hapijs/qs/issues/18) Why is there arrayLimit?
|
||||
- [**#20**](https://github.com/hapijs/qs/issues/20) Configurable parametersLimit
|
||||
- [**#21**](https://github.com/hapijs/qs/issues/21) make all limits optional, for #18, for #20
|
||||
|
||||
## [**1.2.2**](https://github.com/hapijs/qs/issues?milestone=6&state=closed)
|
||||
- [**#19**](https://github.com/hapijs/qs/issues/19) Don't overwrite null values
|
||||
|
||||
## [**1.2.1**](https://github.com/hapijs/qs/issues?milestone=5&state=closed)
|
||||
- [**#16**](https://github.com/hapijs/qs/issues/16) ignore non-string delimiters
|
||||
- [**#15**](https://github.com/hapijs/qs/issues/15) Close code block
|
||||
|
||||
## [**1.2.0**](https://github.com/hapijs/qs/issues?milestone=4&state=closed)
|
||||
- [**#12**](https://github.com/hapijs/qs/issues/12) Add optional delim argument
|
||||
- [**#13**](https://github.com/hapijs/qs/issues/13) fix #11: flattened keys in array are now correctly parsed
|
||||
|
||||
## [**1.1.0**](https://github.com/hapijs/qs/issues?milestone=3&state=closed)
|
||||
- [**#7**](https://github.com/hapijs/qs/issues/7) Empty values of a POST array disappear after being submitted
|
||||
- [**#9**](https://github.com/hapijs/qs/issues/9) Should not omit equals signs (=) when value is null
|
||||
- [**#6**](https://github.com/hapijs/qs/issues/6) Minor grammar fix in README
|
||||
|
||||
## [**1.0.2**](https://github.com/hapijs/qs/issues?milestone=2&state=closed)
|
||||
- [**#5**](https://github.com/hapijs/qs/issues/5) array holes incorrectly copied into object on large index
|
||||
|
1
node_modules/qs/CONTRIBUTING.md
generated
vendored
Normal file
1
node_modules/qs/CONTRIBUTING.md
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
Please view our [hapijs contributing guide](https://github.com/hapijs/hapi/blob/master/CONTRIBUTING.md).
|
28
node_modules/qs/LICENSE
generated
vendored
Executable file
28
node_modules/qs/LICENSE
generated
vendored
Executable file
@ -0,0 +1,28 @@
|
||||
Copyright (c) 2014 Nathan LaFreniere and other contributors.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* The names of any contributors may not be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
* * *
|
||||
|
||||
The complete list of contributors can be found at: https://github.com/hapijs/qs/graphs/contributors
|
8
node_modules/qs/Makefile
generated
vendored
Normal file
8
node_modules/qs/Makefile
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
test:
|
||||
@node node_modules/lab/bin/lab -a code -L
|
||||
test-cov:
|
||||
@node node_modules/lab/bin/lab -a code -t 100 -L
|
||||
test-cov-html:
|
||||
@node node_modules/lab/bin/lab -a code -L -r html -o coverage.html
|
||||
|
||||
.PHONY: test test-cov test-cov-html
|
222
node_modules/qs/README.md
generated
vendored
Executable file
222
node_modules/qs/README.md
generated
vendored
Executable file
@ -0,0 +1,222 @@
|
||||
# qs
|
||||
|
||||
A querystring parsing and stringifying library with some added security.
|
||||
|
||||
[](http://travis-ci.org/hapijs/qs)
|
||||
|
||||
Lead Maintainer: [Nathan LaFreniere](https://github.com/nlf)
|
||||
|
||||
The **qs** module was originally created and maintained by [TJ Holowaychuk](https://github.com/visionmedia/node-querystring).
|
||||
|
||||
## Usage
|
||||
|
||||
```javascript
|
||||
var Qs = require('qs');
|
||||
|
||||
var obj = Qs.parse('a=c'); // { a: 'c' }
|
||||
var str = Qs.stringify(obj); // 'a=c'
|
||||
```
|
||||
|
||||
### Parsing Objects
|
||||
|
||||
```javascript
|
||||
Qs.parse(string, [options]);
|
||||
```
|
||||
|
||||
**qs** allows you to create nested objects within your query strings, by surrounding the name of sub-keys with square brackets `[]`.
|
||||
For example, the string `'foo[bar]=baz'` converts to:
|
||||
|
||||
```javascript
|
||||
{
|
||||
foo: {
|
||||
bar: 'baz'
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
URI encoded strings work too:
|
||||
|
||||
```javascript
|
||||
Qs.parse('a%5Bb%5D=c');
|
||||
// { a: { b: 'c' } }
|
||||
```
|
||||
|
||||
You can also nest your objects, like `'foo[bar][baz]=foobarbaz'`:
|
||||
|
||||
```javascript
|
||||
{
|
||||
foo: {
|
||||
bar: {
|
||||
baz: 'foobarbaz'
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
By default, when nesting objects **qs** will only parse up to 5 children deep. This means if you attempt to parse a string like
|
||||
`'a[b][c][d][e][f][g][h][i]=j'` your resulting object will be:
|
||||
|
||||
```javascript
|
||||
{
|
||||
a: {
|
||||
b: {
|
||||
c: {
|
||||
d: {
|
||||
e: {
|
||||
f: {
|
||||
'[g][h][i]': 'j'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
This depth can be overridden by passing a `depth` option to `Qs.parse(string, [options])`:
|
||||
|
||||
```javascript
|
||||
Qs.parse('a[b][c][d][e][f][g][h][i]=j', { depth: 1 });
|
||||
// { a: { b: { '[c][d][e][f][g][h][i]': 'j' } } }
|
||||
```
|
||||
|
||||
The depth limit helps mitigate abuse when **qs** is used to parse user input, and it is recommended to keep it a reasonably small number.
|
||||
|
||||
For similar reasons, by default **qs** will only parse up to 1000 parameters. This can be overridden by passing a `parameterLimit` option:
|
||||
|
||||
```javascript
|
||||
Qs.parse('a=b&c=d', { parameterLimit: 1 });
|
||||
// { a: 'b' }
|
||||
```
|
||||
|
||||
An optional delimiter can also be passed:
|
||||
|
||||
```javascript
|
||||
Qs.parse('a=b;c=d', { delimiter: ';' });
|
||||
// { a: 'b', c: 'd' }
|
||||
```
|
||||
|
||||
Delimiters can be a regular expression too:
|
||||
|
||||
```javascript
|
||||
Qs.parse('a=b;c=d,e=f', { delimiter: /[;,]/ });
|
||||
// { a: 'b', c: 'd', e: 'f' }
|
||||
```
|
||||
|
||||
### Parsing Arrays
|
||||
|
||||
**qs** can also parse arrays using a similar `[]` notation:
|
||||
|
||||
```javascript
|
||||
Qs.parse('a[]=b&a[]=c');
|
||||
// { a: ['b', 'c'] }
|
||||
```
|
||||
|
||||
You may specify an index as well:
|
||||
|
||||
```javascript
|
||||
Qs.parse('a[1]=c&a[0]=b');
|
||||
// { a: ['b', 'c'] }
|
||||
```
|
||||
|
||||
Note that the only difference between an index in an array and a key in an object is that the value between the brackets must be a number
|
||||
to create an array. When creating arrays with specific indices, **qs** will compact a sparse array to only the existing values preserving
|
||||
their order:
|
||||
|
||||
```javascript
|
||||
Qs.parse('a[1]=b&a[15]=c');
|
||||
// { a: ['b', 'c'] }
|
||||
```
|
||||
|
||||
Note that an empty string is also a value, and will be preserved:
|
||||
|
||||
```javascript
|
||||
Qs.parse('a[]=&a[]=b');
|
||||
// { a: ['', 'b'] }
|
||||
Qs.parse('a[0]=b&a[1]=&a[2]=c');
|
||||
// { a: ['b', '', 'c'] }
|
||||
```
|
||||
|
||||
**qs** will also limit specifying indices in an array to a maximum index of `20`. Any array members with an index of greater than `20` will
|
||||
instead be converted to an object with the index as the key:
|
||||
|
||||
```javascript
|
||||
Qs.parse('a[100]=b');
|
||||
// { a: { '100': 'b' } }
|
||||
```
|
||||
|
||||
This limit can be overridden by passing an `arrayLimit` option:
|
||||
|
||||
```javascript
|
||||
Qs.parse('a[1]=b', { arrayLimit: 0 });
|
||||
// { a: { '1': 'b' } }
|
||||
```
|
||||
|
||||
To disable array parsing entirely, set `arrayLimit` to `-1`.
|
||||
|
||||
If you mix notations, **qs** will merge the two items into an object:
|
||||
|
||||
```javascript
|
||||
Qs.parse('a[0]=b&a[b]=c');
|
||||
// { a: { '0': 'b', b: 'c' } }
|
||||
```
|
||||
|
||||
You can also create arrays of objects:
|
||||
|
||||
```javascript
|
||||
Qs.parse('a[][b]=c');
|
||||
// { a: [{ b: 'c' }] }
|
||||
```
|
||||
|
||||
### Stringifying
|
||||
|
||||
```javascript
|
||||
Qs.stringify(object, [options]);
|
||||
```
|
||||
|
||||
When stringifying, **qs** always URI encodes output. Objects are stringified as you would expect:
|
||||
|
||||
```javascript
|
||||
Qs.stringify({ a: 'b' });
|
||||
// 'a=b'
|
||||
Qs.stringify({ a: { b: 'c' } });
|
||||
// 'a%5Bb%5D=c'
|
||||
```
|
||||
|
||||
Examples beyond this point will be shown as though the output is not URI encoded for clarity. Please note that the return values in these cases *will* be URI encoded during real usage.
|
||||
|
||||
When arrays are stringified, by default they are given explicit indices:
|
||||
|
||||
```javascript
|
||||
Qs.stringify({ a: ['b', 'c', 'd'] });
|
||||
// 'a[0]=b&a[1]=c&a[2]=d'
|
||||
```
|
||||
|
||||
You may override this by setting the `indices` option to `false`:
|
||||
|
||||
```javascript
|
||||
Qs.stringify({ a: ['b', 'c', 'd'] }, { indices: false });
|
||||
// 'a=b&a=c&a=d'
|
||||
```
|
||||
|
||||
Empty strings and null values will omit the value, but the equals sign (=) remains in place:
|
||||
|
||||
```javascript
|
||||
Qs.stringify({ a: '' });
|
||||
// 'a='
|
||||
```
|
||||
|
||||
Properties that are set to `undefined` will be omitted entirely:
|
||||
|
||||
```javascript
|
||||
Qs.stringify({ a: null, b: undefined });
|
||||
// 'a='
|
||||
```
|
||||
|
||||
The delimiter may be overridden with stringify as well:
|
||||
|
||||
```javascript
|
||||
Qs.stringify({ a: 'b', c: 'd' }, { delimiter: ';' });
|
||||
// 'a=b;c=d'
|
||||
```
|
1
node_modules/qs/index.js
generated
vendored
Normal file
1
node_modules/qs/index.js
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
module.exports = require('./lib/');
|
15
node_modules/qs/lib/index.js
generated
vendored
Executable file
15
node_modules/qs/lib/index.js
generated
vendored
Executable file
@ -0,0 +1,15 @@
|
||||
// Load modules
|
||||
|
||||
var Stringify = require('./stringify');
|
||||
var Parse = require('./parse');
|
||||
|
||||
|
||||
// Declare internals
|
||||
|
||||
var internals = {};
|
||||
|
||||
|
||||
module.exports = {
|
||||
stringify: Stringify,
|
||||
parse: Parse
|
||||
};
|
157
node_modules/qs/lib/parse.js
generated
vendored
Executable file
157
node_modules/qs/lib/parse.js
generated
vendored
Executable file
@ -0,0 +1,157 @@
|
||||
// Load modules
|
||||
|
||||
var Utils = require('./utils');
|
||||
|
||||
|
||||
// Declare internals
|
||||
|
||||
var internals = {
|
||||
delimiter: '&',
|
||||
depth: 5,
|
||||
arrayLimit: 20,
|
||||
parameterLimit: 1000
|
||||
};
|
||||
|
||||
|
||||
internals.parseValues = function (str, options) {
|
||||
|
||||
var obj = {};
|
||||
var parts = str.split(options.delimiter, options.parameterLimit === Infinity ? undefined : options.parameterLimit);
|
||||
|
||||
for (var i = 0, il = parts.length; i < il; ++i) {
|
||||
var part = parts[i];
|
||||
var pos = part.indexOf(']=') === -1 ? part.indexOf('=') : part.indexOf(']=') + 1;
|
||||
|
||||
if (pos === -1) {
|
||||
obj[Utils.decode(part)] = '';
|
||||
}
|
||||
else {
|
||||
var key = Utils.decode(part.slice(0, pos));
|
||||
var val = Utils.decode(part.slice(pos + 1));
|
||||
|
||||
if (!obj.hasOwnProperty(key)) {
|
||||
obj[key] = val;
|
||||
}
|
||||
else {
|
||||
obj[key] = [].concat(obj[key]).concat(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
|
||||
internals.parseObject = function (chain, val, options) {
|
||||
|
||||
if (!chain.length) {
|
||||
return val;
|
||||
}
|
||||
|
||||
var root = chain.shift();
|
||||
|
||||
var obj = {};
|
||||
if (root === '[]') {
|
||||
obj = [];
|
||||
obj = obj.concat(internals.parseObject(chain, val, options));
|
||||
}
|
||||
else {
|
||||
var cleanRoot = root[0] === '[' && root[root.length - 1] === ']' ? root.slice(1, root.length - 1) : root;
|
||||
var index = parseInt(cleanRoot, 10);
|
||||
var indexString = '' + index;
|
||||
if (!isNaN(index) &&
|
||||
root !== cleanRoot &&
|
||||
indexString === cleanRoot &&
|
||||
index >= 0 &&
|
||||
index <= options.arrayLimit) {
|
||||
|
||||
obj = [];
|
||||
obj[index] = internals.parseObject(chain, val, options);
|
||||
}
|
||||
else {
|
||||
obj[cleanRoot] = internals.parseObject(chain, val, options);
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
|
||||
internals.parseKeys = function (key, val, options) {
|
||||
|
||||
if (!key) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The regex chunks
|
||||
|
||||
var parent = /^([^\[\]]*)/;
|
||||
var child = /(\[[^\[\]]*\])/g;
|
||||
|
||||
// Get the parent
|
||||
|
||||
var segment = parent.exec(key);
|
||||
|
||||
// Don't allow them to overwrite object prototype properties
|
||||
|
||||
if (Object.prototype.hasOwnProperty(segment[1])) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Stash the parent if it exists
|
||||
|
||||
var keys = [];
|
||||
if (segment[1]) {
|
||||
keys.push(segment[1]);
|
||||
}
|
||||
|
||||
// Loop through children appending to the array until we hit depth
|
||||
|
||||
var i = 0;
|
||||
while ((segment = child.exec(key)) !== null && i < options.depth) {
|
||||
|
||||
++i;
|
||||
if (!Object.prototype.hasOwnProperty(segment[1].replace(/\[|\]/g, ''))) {
|
||||
keys.push(segment[1]);
|
||||
}
|
||||
}
|
||||
|
||||
// If there's a remainder, just add whatever is left
|
||||
|
||||
if (segment) {
|
||||
keys.push('[' + key.slice(segment.index) + ']');
|
||||
}
|
||||
|
||||
return internals.parseObject(keys, val, options);
|
||||
};
|
||||
|
||||
|
||||
module.exports = function (str, options) {
|
||||
|
||||
if (str === '' ||
|
||||
str === null ||
|
||||
typeof str === 'undefined') {
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
options.delimiter = typeof options.delimiter === 'string' || Utils.isRegExp(options.delimiter) ? options.delimiter : internals.delimiter;
|
||||
options.depth = typeof options.depth === 'number' ? options.depth : internals.depth;
|
||||
options.arrayLimit = typeof options.arrayLimit === 'number' ? options.arrayLimit : internals.arrayLimit;
|
||||
options.parameterLimit = typeof options.parameterLimit === 'number' ? options.parameterLimit : internals.parameterLimit;
|
||||
|
||||
var tempObj = typeof str === 'string' ? internals.parseValues(str, options) : str;
|
||||
var obj = {};
|
||||
|
||||
// Iterate over the keys and setup the new object
|
||||
|
||||
var keys = Object.keys(tempObj);
|
||||
for (var i = 0, il = keys.length; i < il; ++i) {
|
||||
var key = keys[i];
|
||||
var newObj = internals.parseKeys(key, tempObj[key], options);
|
||||
obj = Utils.merge(obj, newObj);
|
||||
}
|
||||
|
||||
return Utils.compact(obj);
|
||||
};
|
77
node_modules/qs/lib/stringify.js
generated
vendored
Executable file
77
node_modules/qs/lib/stringify.js
generated
vendored
Executable file
@ -0,0 +1,77 @@
|
||||
// Load modules
|
||||
|
||||
var Utils = require('./utils');
|
||||
|
||||
|
||||
// Declare internals
|
||||
|
||||
var internals = {
|
||||
delimiter: '&',
|
||||
indices: true
|
||||
};
|
||||
|
||||
|
||||
internals.stringify = function (obj, prefix, options) {
|
||||
|
||||
if (Utils.isBuffer(obj)) {
|
||||
obj = obj.toString();
|
||||
}
|
||||
else if (obj instanceof Date) {
|
||||
obj = obj.toISOString();
|
||||
}
|
||||
else if (obj === null) {
|
||||
obj = '';
|
||||
}
|
||||
|
||||
if (typeof obj === 'string' ||
|
||||
typeof obj === 'number' ||
|
||||
typeof obj === 'boolean') {
|
||||
|
||||
return [encodeURIComponent(prefix) + '=' + encodeURIComponent(obj)];
|
||||
}
|
||||
|
||||
var values = [];
|
||||
|
||||
if (typeof obj === 'undefined') {
|
||||
return values;
|
||||
}
|
||||
|
||||
var objKeys = Object.keys(obj);
|
||||
for (var i = 0, il = objKeys.length; i < il; ++i) {
|
||||
var key = objKeys[i];
|
||||
if (!options.indices &&
|
||||
Array.isArray(obj)) {
|
||||
|
||||
values = values.concat(internals.stringify(obj[key], prefix, options));
|
||||
}
|
||||
else {
|
||||
values = values.concat(internals.stringify(obj[key], prefix + '[' + key + ']', options));
|
||||
}
|
||||
}
|
||||
|
||||
return values;
|
||||
};
|
||||
|
||||
|
||||
module.exports = function (obj, options) {
|
||||
|
||||
options = options || {};
|
||||
var delimiter = typeof options.delimiter === 'undefined' ? internals.delimiter : options.delimiter;
|
||||
options.indices = typeof options.indices === 'boolean' ? options.indices : internals.indices;
|
||||
|
||||
var keys = [];
|
||||
|
||||
if (typeof obj !== 'object' ||
|
||||
obj === null) {
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
var objKeys = Object.keys(obj);
|
||||
for (var i = 0, il = objKeys.length; i < il; ++i) {
|
||||
var key = objKeys[i];
|
||||
keys = keys.concat(internals.stringify(obj[key], key, options));
|
||||
}
|
||||
|
||||
return keys.join(delimiter);
|
||||
};
|
132
node_modules/qs/lib/utils.js
generated
vendored
Executable file
132
node_modules/qs/lib/utils.js
generated
vendored
Executable file
@ -0,0 +1,132 @@
|
||||
// Load modules
|
||||
|
||||
|
||||
// Declare internals
|
||||
|
||||
var internals = {};
|
||||
|
||||
|
||||
exports.arrayToObject = function (source) {
|
||||
|
||||
var obj = {};
|
||||
for (var i = 0, il = source.length; i < il; ++i) {
|
||||
if (typeof source[i] !== 'undefined') {
|
||||
|
||||
obj[i] = source[i];
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
|
||||
exports.merge = function (target, source) {
|
||||
|
||||
if (!source) {
|
||||
return target;
|
||||
}
|
||||
|
||||
if (typeof source !== 'object') {
|
||||
if (Array.isArray(target)) {
|
||||
target.push(source);
|
||||
}
|
||||
else {
|
||||
target[source] = true;
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
if (typeof target !== 'object') {
|
||||
target = [target].concat(source);
|
||||
return target;
|
||||
}
|
||||
|
||||
if (Array.isArray(target) &&
|
||||
!Array.isArray(source)) {
|
||||
|
||||
target = exports.arrayToObject(target);
|
||||
}
|
||||
|
||||
var keys = Object.keys(source);
|
||||
for (var k = 0, kl = keys.length; k < kl; ++k) {
|
||||
var key = keys[k];
|
||||
var value = source[key];
|
||||
|
||||
if (!target[key]) {
|
||||
target[key] = value;
|
||||
}
|
||||
else {
|
||||
target[key] = exports.merge(target[key], value);
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
||||
|
||||
|
||||
exports.decode = function (str) {
|
||||
|
||||
try {
|
||||
return decodeURIComponent(str.replace(/\+/g, ' '));
|
||||
} catch (e) {
|
||||
return str;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
exports.compact = function (obj, refs) {
|
||||
|
||||
if (typeof obj !== 'object' ||
|
||||
obj === null) {
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
refs = refs || [];
|
||||
var lookup = refs.indexOf(obj);
|
||||
if (lookup !== -1) {
|
||||
return refs[lookup];
|
||||
}
|
||||
|
||||
refs.push(obj);
|
||||
|
||||
if (Array.isArray(obj)) {
|
||||
var compacted = [];
|
||||
|
||||
for (var i = 0, il = obj.length; i < il; ++i) {
|
||||
if (typeof obj[i] !== 'undefined') {
|
||||
compacted.push(obj[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return compacted;
|
||||
}
|
||||
|
||||
var keys = Object.keys(obj);
|
||||
for (i = 0, il = keys.length; i < il; ++i) {
|
||||
var key = keys[i];
|
||||
obj[key] = exports.compact(obj[key], refs);
|
||||
}
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
|
||||
exports.isRegExp = function (obj) {
|
||||
return Object.prototype.toString.call(obj) === '[object RegExp]';
|
||||
};
|
||||
|
||||
|
||||
exports.isBuffer = function (obj) {
|
||||
|
||||
if (obj === null ||
|
||||
typeof obj === 'undefined') {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return !!(obj.constructor &&
|
||||
obj.constructor.isBuffer &&
|
||||
obj.constructor.isBuffer(obj));
|
||||
};
|
92
node_modules/qs/package.json
generated
vendored
Normal file
92
node_modules/qs/package.json
generated
vendored
Normal file
@ -0,0 +1,92 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"raw": "qs@2.3.3",
|
||||
"scope": null,
|
||||
"escapedName": "qs",
|
||||
"name": "qs",
|
||||
"rawSpec": "2.3.3",
|
||||
"spec": "2.3.3",
|
||||
"type": "version"
|
||||
},
|
||||
"/home/burchettm/statsbot/node_modules/superagent"
|
||||
]
|
||||
],
|
||||
"_from": "qs@2.3.3",
|
||||
"_id": "qs@2.3.3",
|
||||
"_inCache": true,
|
||||
"_location": "/qs",
|
||||
"_nodeVersion": "0.10.32",
|
||||
"_npmUser": {
|
||||
"name": "nlf",
|
||||
"email": "quitlahok@gmail.com"
|
||||
},
|
||||
"_npmVersion": "2.1.6",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"raw": "qs@2.3.3",
|
||||
"scope": null,
|
||||
"escapedName": "qs",
|
||||
"name": "qs",
|
||||
"rawSpec": "2.3.3",
|
||||
"spec": "2.3.3",
|
||||
"type": "version"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/superagent"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/qs/-/qs-2.3.3.tgz",
|
||||
"_shasum": "e9e85adbe75da0bbe4c8e0476a086290f863b404",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "qs@2.3.3",
|
||||
"_where": "/home/burchettm/statsbot/node_modules/superagent",
|
||||
"bugs": {
|
||||
"url": "https://github.com/hapijs/qs/issues"
|
||||
},
|
||||
"dependencies": {},
|
||||
"description": "A querystring parser that supports nesting and arrays, with a depth limit",
|
||||
"devDependencies": {
|
||||
"code": "1.x.x",
|
||||
"lab": "5.x.x"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "e9e85adbe75da0bbe4c8e0476a086290f863b404",
|
||||
"tarball": "https://registry.npmjs.org/qs/-/qs-2.3.3.tgz"
|
||||
},
|
||||
"gitHead": "9250c4cda5102fcf72441445816e6d311fc6813d",
|
||||
"homepage": "https://github.com/hapijs/qs",
|
||||
"keywords": [
|
||||
"querystring",
|
||||
"qs"
|
||||
],
|
||||
"licenses": [
|
||||
{
|
||||
"type": "BSD",
|
||||
"url": "http://github.com/hapijs/qs/raw/master/LICENSE"
|
||||
}
|
||||
],
|
||||
"main": "index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "nlf",
|
||||
"email": "quitlahok@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "hueniverse",
|
||||
"email": "eran@hueniverse.com"
|
||||
}
|
||||
],
|
||||
"name": "qs",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/hapijs/qs.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "make test-cov"
|
||||
},
|
||||
"version": "2.3.3"
|
||||
}
|
413
node_modules/qs/test/parse.js
generated
vendored
Executable file
413
node_modules/qs/test/parse.js
generated
vendored
Executable file
@ -0,0 +1,413 @@
|
||||
/* eslint no-extend-native:0 */
|
||||
// Load modules
|
||||
|
||||
var Code = require('code');
|
||||
var Lab = require('lab');
|
||||
var Qs = require('../');
|
||||
|
||||
|
||||
// Declare internals
|
||||
|
||||
var internals = {};
|
||||
|
||||
|
||||
// Test shortcuts
|
||||
|
||||
var lab = exports.lab = Lab.script();
|
||||
var expect = Code.expect;
|
||||
var describe = lab.experiment;
|
||||
var it = lab.test;
|
||||
|
||||
|
||||
describe('parse()', function () {
|
||||
|
||||
it('parses a simple string', function (done) {
|
||||
|
||||
expect(Qs.parse('0=foo')).to.deep.equal({ '0': 'foo' });
|
||||
expect(Qs.parse('foo=c++')).to.deep.equal({ foo: 'c ' });
|
||||
expect(Qs.parse('a[>=]=23')).to.deep.equal({ a: { '>=': '23' } });
|
||||
expect(Qs.parse('a[<=>]==23')).to.deep.equal({ a: { '<=>': '=23' } });
|
||||
expect(Qs.parse('a[==]=23')).to.deep.equal({ a: { '==': '23' } });
|
||||
expect(Qs.parse('foo')).to.deep.equal({ foo: '' });
|
||||
expect(Qs.parse('foo=bar')).to.deep.equal({ foo: 'bar' });
|
||||
expect(Qs.parse(' foo = bar = baz ')).to.deep.equal({ ' foo ': ' bar = baz ' });
|
||||
expect(Qs.parse('foo=bar=baz')).to.deep.equal({ foo: 'bar=baz' });
|
||||
expect(Qs.parse('foo=bar&bar=baz')).to.deep.equal({ foo: 'bar', bar: 'baz' });
|
||||
expect(Qs.parse('foo=bar&baz')).to.deep.equal({ foo: 'bar', baz: '' });
|
||||
expect(Qs.parse('cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World')).to.deep.equal({
|
||||
cht: 'p3',
|
||||
chd: 't:60,40',
|
||||
chs: '250x100',
|
||||
chl: 'Hello|World'
|
||||
});
|
||||
done();
|
||||
});
|
||||
|
||||
it('parses a single nested string', function (done) {
|
||||
|
||||
expect(Qs.parse('a[b]=c')).to.deep.equal({ a: { b: 'c' } });
|
||||
done();
|
||||
});
|
||||
|
||||
it('parses a double nested string', function (done) {
|
||||
|
||||
expect(Qs.parse('a[b][c]=d')).to.deep.equal({ a: { b: { c: 'd' } } });
|
||||
done();
|
||||
});
|
||||
|
||||
it('defaults to a depth of 5', function (done) {
|
||||
|
||||
expect(Qs.parse('a[b][c][d][e][f][g][h]=i')).to.deep.equal({ a: { b: { c: { d: { e: { f: { '[g][h]': 'i' } } } } } } });
|
||||
done();
|
||||
});
|
||||
|
||||
it('only parses one level when depth = 1', function (done) {
|
||||
|
||||
expect(Qs.parse('a[b][c]=d', { depth: 1 })).to.deep.equal({ a: { b: { '[c]': 'd' } } });
|
||||
expect(Qs.parse('a[b][c][d]=e', { depth: 1 })).to.deep.equal({ a: { b: { '[c][d]': 'e' } } });
|
||||
done();
|
||||
});
|
||||
|
||||
it('parses a simple array', function (done) {
|
||||
|
||||
expect(Qs.parse('a=b&a=c')).to.deep.equal({ a: ['b', 'c'] });
|
||||
done();
|
||||
});
|
||||
|
||||
it('parses an explicit array', function (done) {
|
||||
|
||||
expect(Qs.parse('a[]=b')).to.deep.equal({ a: ['b'] });
|
||||
expect(Qs.parse('a[]=b&a[]=c')).to.deep.equal({ a: ['b', 'c'] });
|
||||
expect(Qs.parse('a[]=b&a[]=c&a[]=d')).to.deep.equal({ a: ['b', 'c', 'd'] });
|
||||
done();
|
||||
});
|
||||
|
||||
it('parses a mix of simple and explicit arrays', function (done) {
|
||||
|
||||
expect(Qs.parse('a=b&a[]=c')).to.deep.equal({ a: ['b', 'c'] });
|
||||
expect(Qs.parse('a[]=b&a=c')).to.deep.equal({ a: ['b', 'c'] });
|
||||
expect(Qs.parse('a[0]=b&a=c')).to.deep.equal({ a: ['b', 'c'] });
|
||||
expect(Qs.parse('a=b&a[0]=c')).to.deep.equal({ a: ['b', 'c'] });
|
||||
expect(Qs.parse('a[1]=b&a=c')).to.deep.equal({ a: ['b', 'c'] });
|
||||
expect(Qs.parse('a=b&a[1]=c')).to.deep.equal({ a: ['b', 'c'] });
|
||||
done();
|
||||
});
|
||||
|
||||
it('parses a nested array', function (done) {
|
||||
|
||||
expect(Qs.parse('a[b][]=c&a[b][]=d')).to.deep.equal({ a: { b: ['c', 'd'] } });
|
||||
expect(Qs.parse('a[>=]=25')).to.deep.equal({ a: { '>=': '25' } });
|
||||
done();
|
||||
});
|
||||
|
||||
it('allows to specify array indices', function (done) {
|
||||
|
||||
expect(Qs.parse('a[1]=c&a[0]=b&a[2]=d')).to.deep.equal({ a: ['b', 'c', 'd'] });
|
||||
expect(Qs.parse('a[1]=c&a[0]=b')).to.deep.equal({ a: ['b', 'c'] });
|
||||
expect(Qs.parse('a[1]=c')).to.deep.equal({ a: ['c'] });
|
||||
done();
|
||||
});
|
||||
|
||||
it('limits specific array indices to 20', function (done) {
|
||||
|
||||
expect(Qs.parse('a[20]=a')).to.deep.equal({ a: ['a'] });
|
||||
expect(Qs.parse('a[21]=a')).to.deep.equal({ a: { '21': 'a' } });
|
||||
done();
|
||||
});
|
||||
|
||||
it('supports keys that begin with a number', function (done) {
|
||||
|
||||
expect(Qs.parse('a[12b]=c')).to.deep.equal({ a: { '12b': 'c' } });
|
||||
done();
|
||||
});
|
||||
|
||||
it('supports encoded = signs', function (done) {
|
||||
|
||||
expect(Qs.parse('he%3Dllo=th%3Dere')).to.deep.equal({ 'he=llo': 'th=ere' });
|
||||
done();
|
||||
});
|
||||
|
||||
it('is ok with url encoded strings', function (done) {
|
||||
|
||||
expect(Qs.parse('a[b%20c]=d')).to.deep.equal({ a: { 'b c': 'd' } });
|
||||
expect(Qs.parse('a[b]=c%20d')).to.deep.equal({ a: { b: 'c d' } });
|
||||
done();
|
||||
});
|
||||
|
||||
it('allows brackets in the value', function (done) {
|
||||
|
||||
expect(Qs.parse('pets=["tobi"]')).to.deep.equal({ pets: '["tobi"]' });
|
||||
expect(Qs.parse('operators=[">=", "<="]')).to.deep.equal({ operators: '[">=", "<="]' });
|
||||
done();
|
||||
});
|
||||
|
||||
it('allows empty values', function (done) {
|
||||
|
||||
expect(Qs.parse('')).to.deep.equal({});
|
||||
expect(Qs.parse(null)).to.deep.equal({});
|
||||
expect(Qs.parse(undefined)).to.deep.equal({});
|
||||
done();
|
||||
});
|
||||
|
||||
it('transforms arrays to objects', function (done) {
|
||||
|
||||
expect(Qs.parse('foo[0]=bar&foo[bad]=baz')).to.deep.equal({ foo: { '0': 'bar', bad: 'baz' } });
|
||||
expect(Qs.parse('foo[bad]=baz&foo[0]=bar')).to.deep.equal({ foo: { bad: 'baz', '0': 'bar' } });
|
||||
expect(Qs.parse('foo[bad]=baz&foo[]=bar')).to.deep.equal({ foo: { bad: 'baz', '0': 'bar' } });
|
||||
expect(Qs.parse('foo[]=bar&foo[bad]=baz')).to.deep.equal({ foo: { '0': 'bar', bad: 'baz' } });
|
||||
expect(Qs.parse('foo[bad]=baz&foo[]=bar&foo[]=foo')).to.deep.equal({ foo: { bad: 'baz', '0': 'bar', '1': 'foo' } });
|
||||
expect(Qs.parse('foo[0][a]=a&foo[0][b]=b&foo[1][a]=aa&foo[1][b]=bb')).to.deep.equal({foo: [ {a: 'a', b: 'b'}, {a: 'aa', b: 'bb'} ]});
|
||||
done();
|
||||
});
|
||||
|
||||
it('can add keys to objects', function (done) {
|
||||
|
||||
expect(Qs.parse('a[b]=c&a=d')).to.deep.equal({ a: { b: 'c', d: true } });
|
||||
done();
|
||||
});
|
||||
|
||||
it('correctly prunes undefined values when converting an array to an object', function (done) {
|
||||
|
||||
expect(Qs.parse('a[2]=b&a[99999999]=c')).to.deep.equal({ a: { '2': 'b', '99999999': 'c' } });
|
||||
done();
|
||||
});
|
||||
|
||||
it('supports malformed uri characters', function (done) {
|
||||
|
||||
expect(Qs.parse('{%:%}')).to.deep.equal({ '{%:%}': '' });
|
||||
expect(Qs.parse('foo=%:%}')).to.deep.equal({ foo: '%:%}' });
|
||||
done();
|
||||
});
|
||||
|
||||
it('doesn\'t produce empty keys', function (done) {
|
||||
|
||||
expect(Qs.parse('_r=1&')).to.deep.equal({ '_r': '1' });
|
||||
done();
|
||||
});
|
||||
|
||||
it('cannot override prototypes', function (done) {
|
||||
|
||||
var obj = Qs.parse('toString=bad&bad[toString]=bad&constructor=bad');
|
||||
expect(typeof obj.toString).to.equal('function');
|
||||
expect(typeof obj.bad.toString).to.equal('function');
|
||||
expect(typeof obj.constructor).to.equal('function');
|
||||
done();
|
||||
});
|
||||
|
||||
it('cannot access Object prototype', function (done) {
|
||||
|
||||
Qs.parse('constructor[prototype][bad]=bad');
|
||||
Qs.parse('bad[constructor][prototype][bad]=bad');
|
||||
expect(typeof Object.prototype.bad).to.equal('undefined');
|
||||
done();
|
||||
});
|
||||
|
||||
it('parses arrays of objects', function (done) {
|
||||
|
||||
expect(Qs.parse('a[][b]=c')).to.deep.equal({ a: [{ b: 'c' }] });
|
||||
expect(Qs.parse('a[0][b]=c')).to.deep.equal({ a: [{ b: 'c' }] });
|
||||
done();
|
||||
});
|
||||
|
||||
it('allows for empty strings in arrays', function (done) {
|
||||
|
||||
expect(Qs.parse('a[]=b&a[]=&a[]=c')).to.deep.equal({ a: ['b', '', 'c'] });
|
||||
expect(Qs.parse('a[0]=b&a[1]=&a[2]=c&a[19]=')).to.deep.equal({ a: ['b', '', 'c', ''] });
|
||||
expect(Qs.parse('a[]=&a[]=b&a[]=c')).to.deep.equal({ a: ['', 'b', 'c'] });
|
||||
done();
|
||||
});
|
||||
|
||||
it('compacts sparse arrays', function (done) {
|
||||
|
||||
expect(Qs.parse('a[10]=1&a[2]=2')).to.deep.equal({ a: ['2', '1'] });
|
||||
done();
|
||||
});
|
||||
|
||||
it('parses semi-parsed strings', function (done) {
|
||||
|
||||
expect(Qs.parse({ 'a[b]': 'c' })).to.deep.equal({ a: { b: 'c' } });
|
||||
expect(Qs.parse({ 'a[b]': 'c', 'a[d]': 'e' })).to.deep.equal({ a: { b: 'c', d: 'e' } });
|
||||
done();
|
||||
});
|
||||
|
||||
it('parses buffers correctly', function (done) {
|
||||
|
||||
var b = new Buffer('test');
|
||||
expect(Qs.parse({ a: b })).to.deep.equal({ a: b });
|
||||
done();
|
||||
});
|
||||
|
||||
it('continues parsing when no parent is found', function (done) {
|
||||
|
||||
expect(Qs.parse('[]&a=b')).to.deep.equal({ '0': '', a: 'b' });
|
||||
expect(Qs.parse('[foo]=bar')).to.deep.equal({ foo: 'bar' });
|
||||
done();
|
||||
});
|
||||
|
||||
it('does not error when parsing a very long array', function (done) {
|
||||
|
||||
var str = 'a[]=a';
|
||||
while (Buffer.byteLength(str) < 128 * 1024) {
|
||||
str += '&' + str;
|
||||
}
|
||||
|
||||
expect(function () {
|
||||
|
||||
Qs.parse(str);
|
||||
}).to.not.throw();
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('should not throw when a native prototype has an enumerable property', { parallel: false }, function (done) {
|
||||
|
||||
Object.prototype.crash = '';
|
||||
Array.prototype.crash = '';
|
||||
expect(Qs.parse.bind(null, 'a=b')).to.not.throw();
|
||||
expect(Qs.parse('a=b')).to.deep.equal({ a: 'b' });
|
||||
expect(Qs.parse.bind(null, 'a[][b]=c')).to.not.throw();
|
||||
expect(Qs.parse('a[][b]=c')).to.deep.equal({ a: [{ b: 'c' }] });
|
||||
delete Object.prototype.crash;
|
||||
delete Array.prototype.crash;
|
||||
done();
|
||||
});
|
||||
|
||||
it('parses a string with an alternative string delimiter', function (done) {
|
||||
|
||||
expect(Qs.parse('a=b;c=d', { delimiter: ';' })).to.deep.equal({ a: 'b', c: 'd' });
|
||||
done();
|
||||
});
|
||||
|
||||
it('parses a string with an alternative RegExp delimiter', function (done) {
|
||||
|
||||
expect(Qs.parse('a=b; c=d', { delimiter: /[;,] */ })).to.deep.equal({ a: 'b', c: 'd' });
|
||||
done();
|
||||
});
|
||||
|
||||
it('does not use non-splittable objects as delimiters', function (done) {
|
||||
|
||||
expect(Qs.parse('a=b&c=d', { delimiter: true })).to.deep.equal({ a: 'b', c: 'd' });
|
||||
done();
|
||||
});
|
||||
|
||||
it('allows overriding parameter limit', function (done) {
|
||||
|
||||
expect(Qs.parse('a=b&c=d', { parameterLimit: 1 })).to.deep.equal({ a: 'b' });
|
||||
done();
|
||||
});
|
||||
|
||||
it('allows setting the parameter limit to Infinity', function (done) {
|
||||
|
||||
expect(Qs.parse('a=b&c=d', { parameterLimit: Infinity })).to.deep.equal({ a: 'b', c: 'd' });
|
||||
done();
|
||||
});
|
||||
|
||||
it('allows overriding array limit', function (done) {
|
||||
|
||||
expect(Qs.parse('a[0]=b', { arrayLimit: -1 })).to.deep.equal({ a: { '0': 'b' } });
|
||||
expect(Qs.parse('a[-1]=b', { arrayLimit: -1 })).to.deep.equal({ a: { '-1': 'b' } });
|
||||
expect(Qs.parse('a[0]=b&a[1]=c', { arrayLimit: 0 })).to.deep.equal({ a: { '0': 'b', '1': 'c' } });
|
||||
done();
|
||||
});
|
||||
|
||||
it('parses an object', function (done) {
|
||||
|
||||
var input = {
|
||||
'user[name]': {'pop[bob]': 3},
|
||||
'user[email]': null
|
||||
};
|
||||
|
||||
var expected = {
|
||||
'user': {
|
||||
'name': {'pop[bob]': 3},
|
||||
'email': null
|
||||
}
|
||||
};
|
||||
|
||||
var result = Qs.parse(input);
|
||||
|
||||
expect(result).to.deep.equal(expected);
|
||||
done();
|
||||
});
|
||||
|
||||
it('parses an object and not child values', function (done) {
|
||||
|
||||
var input = {
|
||||
'user[name]': {'pop[bob]': { 'test': 3 }},
|
||||
'user[email]': null
|
||||
};
|
||||
|
||||
var expected = {
|
||||
'user': {
|
||||
'name': {'pop[bob]': { 'test': 3 }},
|
||||
'email': null
|
||||
}
|
||||
};
|
||||
|
||||
var result = Qs.parse(input);
|
||||
|
||||
expect(result).to.deep.equal(expected);
|
||||
done();
|
||||
});
|
||||
|
||||
it('does not blow up when Buffer global is missing', function (done) {
|
||||
|
||||
var tempBuffer = global.Buffer;
|
||||
delete global.Buffer;
|
||||
var result = Qs.parse('a=b&c=d');
|
||||
global.Buffer = tempBuffer;
|
||||
expect(result).to.deep.equal({ a: 'b', c: 'd' });
|
||||
done();
|
||||
});
|
||||
|
||||
it('does not crash when using invalid dot notation', function (done) {
|
||||
|
||||
expect(Qs.parse('roomInfoList[0].childrenAges[0]=15&roomInfoList[0].numberOfAdults=2')).to.deep.equal({ roomInfoList: [['15', '2']] });
|
||||
done();
|
||||
});
|
||||
|
||||
it('does not crash when parsing circular references', function (done) {
|
||||
|
||||
var a = {};
|
||||
a.b = a;
|
||||
|
||||
var parsed;
|
||||
|
||||
expect(function () {
|
||||
|
||||
parsed = Qs.parse({ 'foo[bar]': 'baz', 'foo[baz]': a });
|
||||
}).to.not.throw();
|
||||
|
||||
expect(parsed).to.contain('foo');
|
||||
expect(parsed.foo).to.contain('bar', 'baz');
|
||||
expect(parsed.foo.bar).to.equal('baz');
|
||||
expect(parsed.foo.baz).to.deep.equal(a);
|
||||
done();
|
||||
});
|
||||
|
||||
it('parses plain objects correctly', function (done) {
|
||||
|
||||
var a = Object.create(null);
|
||||
a.b = 'c';
|
||||
|
||||
expect(Qs.parse(a)).to.deep.equal({ b: 'c' });
|
||||
var result = Qs.parse({ a: a });
|
||||
expect(result).to.contain('a');
|
||||
expect(result.a).to.deep.equal(a);
|
||||
done();
|
||||
});
|
||||
|
||||
it('parses dates correctly', function (done) {
|
||||
|
||||
var now = new Date();
|
||||
expect(Qs.parse({ a: now })).to.deep.equal({ a: now });
|
||||
done();
|
||||
});
|
||||
|
||||
it('parses regular expressions correctly', function (done) {
|
||||
|
||||
var re = /^test$/;
|
||||
expect(Qs.parse({ a: re })).to.deep.equal({ a: re });
|
||||
done();
|
||||
});
|
||||
});
|
179
node_modules/qs/test/stringify.js
generated
vendored
Executable file
179
node_modules/qs/test/stringify.js
generated
vendored
Executable file
@ -0,0 +1,179 @@
|
||||
/* eslint no-extend-native:0 */
|
||||
// Load modules
|
||||
|
||||
var Code = require('code');
|
||||
var Lab = require('lab');
|
||||
var Qs = require('../');
|
||||
|
||||
|
||||
// Declare internals
|
||||
|
||||
var internals = {};
|
||||
|
||||
|
||||
// Test shortcuts
|
||||
|
||||
var lab = exports.lab = Lab.script();
|
||||
var expect = Code.expect;
|
||||
var describe = lab.experiment;
|
||||
var it = lab.test;
|
||||
|
||||
|
||||
describe('stringify()', function () {
|
||||
|
||||
it('stringifies a querystring object', function (done) {
|
||||
|
||||
expect(Qs.stringify({ a: 'b' })).to.equal('a=b');
|
||||
expect(Qs.stringify({ a: 1 })).to.equal('a=1');
|
||||
expect(Qs.stringify({ a: 1, b: 2 })).to.equal('a=1&b=2');
|
||||
done();
|
||||
});
|
||||
|
||||
it('stringifies a nested object', function (done) {
|
||||
|
||||
expect(Qs.stringify({ a: { b: 'c' } })).to.equal('a%5Bb%5D=c');
|
||||
expect(Qs.stringify({ a: { b: { c: { d: 'e' } } } })).to.equal('a%5Bb%5D%5Bc%5D%5Bd%5D=e');
|
||||
done();
|
||||
});
|
||||
|
||||
it('stringifies an array value', function (done) {
|
||||
|
||||
expect(Qs.stringify({ a: ['b', 'c', 'd'] })).to.equal('a%5B0%5D=b&a%5B1%5D=c&a%5B2%5D=d');
|
||||
done();
|
||||
});
|
||||
|
||||
it('omits array indices when asked', function (done) {
|
||||
|
||||
expect(Qs.stringify({ a: ['b', 'c', 'd'] }, { indices: false })).to.equal('a=b&a=c&a=d');
|
||||
done();
|
||||
});
|
||||
|
||||
it('stringifies a nested array value', function (done) {
|
||||
|
||||
expect(Qs.stringify({ a: { b: ['c', 'd'] } })).to.equal('a%5Bb%5D%5B0%5D=c&a%5Bb%5D%5B1%5D=d');
|
||||
done();
|
||||
});
|
||||
|
||||
it('stringifies an object inside an array', function (done) {
|
||||
|
||||
expect(Qs.stringify({ a: [{ b: 'c' }] })).to.equal('a%5B0%5D%5Bb%5D=c');
|
||||
expect(Qs.stringify({ a: [{ b: { c: [1] } }] })).to.equal('a%5B0%5D%5Bb%5D%5Bc%5D%5B0%5D=1');
|
||||
done();
|
||||
});
|
||||
|
||||
it('does not omit object keys when indices = false', function (done) {
|
||||
|
||||
expect(Qs.stringify({ a: [{ b: 'c' }] }, { indices: false })).to.equal('a%5Bb%5D=c');
|
||||
done();
|
||||
});
|
||||
|
||||
it('stringifies a complicated object', function (done) {
|
||||
|
||||
expect(Qs.stringify({ a: { b: 'c', d: 'e' } })).to.equal('a%5Bb%5D=c&a%5Bd%5D=e');
|
||||
done();
|
||||
});
|
||||
|
||||
it('stringifies an empty value', function (done) {
|
||||
|
||||
expect(Qs.stringify({ a: '' })).to.equal('a=');
|
||||
expect(Qs.stringify({ a: '', b: '' })).to.equal('a=&b=');
|
||||
expect(Qs.stringify({ a: null })).to.equal('a=');
|
||||
expect(Qs.stringify({ a: { b: null } })).to.equal('a%5Bb%5D=');
|
||||
done();
|
||||
});
|
||||
|
||||
it('stringifies an empty object', function (done) {
|
||||
|
||||
var obj = Object.create(null);
|
||||
obj.a = 'b';
|
||||
expect(Qs.stringify(obj)).to.equal('a=b');
|
||||
done();
|
||||
});
|
||||
|
||||
it('returns an empty string for invalid input', function (done) {
|
||||
|
||||
expect(Qs.stringify(undefined)).to.equal('');
|
||||
expect(Qs.stringify(false)).to.equal('');
|
||||
expect(Qs.stringify(null)).to.equal('');
|
||||
expect(Qs.stringify('')).to.equal('');
|
||||
done();
|
||||
});
|
||||
|
||||
it('stringifies an object with an empty object as a child', function (done) {
|
||||
|
||||
var obj = {
|
||||
a: Object.create(null)
|
||||
};
|
||||
|
||||
obj.a.b = 'c';
|
||||
expect(Qs.stringify(obj)).to.equal('a%5Bb%5D=c');
|
||||
done();
|
||||
});
|
||||
|
||||
it('drops keys with a value of undefined', function (done) {
|
||||
|
||||
expect(Qs.stringify({ a: undefined })).to.equal('');
|
||||
expect(Qs.stringify({ a: { b: undefined, c: null } })).to.equal('a%5Bc%5D=');
|
||||
done();
|
||||
});
|
||||
|
||||
it('url encodes values', function (done) {
|
||||
|
||||
expect(Qs.stringify({ a: 'b c' })).to.equal('a=b%20c');
|
||||
done();
|
||||
});
|
||||
|
||||
it('stringifies a date', function (done) {
|
||||
|
||||
var now = new Date();
|
||||
var str = 'a=' + encodeURIComponent(now.toISOString());
|
||||
expect(Qs.stringify({ a: now })).to.equal(str);
|
||||
done();
|
||||
});
|
||||
|
||||
it('stringifies the weird object from qs', function (done) {
|
||||
|
||||
expect(Qs.stringify({ 'my weird field': 'q1!2"\'w$5&7/z8)?' })).to.equal('my%20weird%20field=q1!2%22\'w%245%267%2Fz8)%3F');
|
||||
done();
|
||||
});
|
||||
|
||||
it('skips properties that are part of the object prototype', function (done) {
|
||||
|
||||
Object.prototype.crash = 'test';
|
||||
expect(Qs.stringify({ a: 'b'})).to.equal('a=b');
|
||||
expect(Qs.stringify({ a: { b: 'c' } })).to.equal('a%5Bb%5D=c');
|
||||
delete Object.prototype.crash;
|
||||
done();
|
||||
});
|
||||
|
||||
it('stringifies boolean values', function (done) {
|
||||
|
||||
expect(Qs.stringify({ a: true })).to.equal('a=true');
|
||||
expect(Qs.stringify({ a: { b: true } })).to.equal('a%5Bb%5D=true');
|
||||
expect(Qs.stringify({ b: false })).to.equal('b=false');
|
||||
expect(Qs.stringify({ b: { c: false } })).to.equal('b%5Bc%5D=false');
|
||||
done();
|
||||
});
|
||||
|
||||
it('stringifies buffer values', function (done) {
|
||||
|
||||
expect(Qs.stringify({ a: new Buffer('test') })).to.equal('a=test');
|
||||
expect(Qs.stringify({ a: { b: new Buffer('test') } })).to.equal('a%5Bb%5D=test');
|
||||
done();
|
||||
});
|
||||
|
||||
it('stringifies an object using an alternative delimiter', function (done) {
|
||||
|
||||
expect(Qs.stringify({ a: 'b', c: 'd' }, { delimiter: ';' })).to.equal('a=b;c=d');
|
||||
done();
|
||||
});
|
||||
|
||||
it('doesn\'t blow up when Buffer global is missing', function (done) {
|
||||
|
||||
var tempBuffer = global.Buffer;
|
||||
delete global.Buffer;
|
||||
expect(Qs.stringify({ a: 'b', c: 'd' })).to.equal('a=b&c=d');
|
||||
global.Buffer = tempBuffer;
|
||||
done();
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user