Socket
Socket
Sign inDemoInstall

qs

Package Overview
Dependencies
0
Maintainers
2
Versions
110
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.2.0 to 6.0.0

2

bower.json
{
"name": "qs",
"main": "dist/qs.js",
"version": "5.1.0",
"version": "5.2.0",
"homepage": "https://github.com/hapijs/qs",

@@ -6,0 +6,0 @@ "authors": [

@@ -5,3 +5,3 @@ {

"description": "query-string parser / stringifier with nesting support",
"version": "5.1.0",
"version": "5.2.0",
"keywords": ["querystring", "query", "parser"],

@@ -8,0 +8,0 @@ "main": "lib/index.js",

@@ -237,3 +237,3 @@ (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){

internals.stringify = function (obj, prefix, generateArrayPrefix, strictNullHandling, skipNulls, encode, filter) {
internals.stringify = function (obj, prefix, generateArrayPrefix, strictNullHandling, skipNulls, encode, filter, sort) {

@@ -273,3 +273,10 @@ if (typeof filter === 'function') {

var objKeys = Array.isArray(filter) ? filter : Object.keys(obj);
var objKeys;
if (Array.isArray(filter)) {
objKeys = filter;
} else {
var keys = Object.keys(obj);
objKeys = sort ? keys.sort(sort) : keys;
}
for (var i = 0, il = objKeys.length; i < il; ++i) {

@@ -303,2 +310,3 @@ var key = objKeys[i];

var encode = typeof options.encode === 'boolean' ? options.encode : internals.encode;
var sort = typeof options.sort === 'function' ? options.sort : null;
var objKeys;

@@ -339,2 +347,6 @@ var filter;

if (sort) {
objKeys.sort(sort);
}
for (var i = 0, il = objKeys.length; i < il; ++i) {

@@ -349,3 +361,3 @@ var key = objKeys[i];

keys = keys.concat(internals.stringify(obj[key], key, generateArrayPrefix, strictNullHandling, skipNulls, encode, filter));
keys = keys.concat(internals.stringify(obj[key], key, generateArrayPrefix, strictNullHandling, skipNulls, encode, filter, sort));
}

@@ -352,0 +364,0 @@

@@ -0,5 +1,7 @@

'use strict';
// Load modules
var Stringify = require('./stringify');
var Parse = require('./parse');
const Stringify = require('./stringify');
const Parse = require('./parse');

@@ -9,8 +11,6 @@

var internals = {};
const internals = {};
module.exports = {
stringify: Stringify,
parse: Parse
};
exports.stringify = Stringify;
exports.parse = Parse;

@@ -0,4 +1,6 @@

'use strict';
// Load modules
var Utils = require('./utils');
const Utils = require('./utils');

@@ -8,3 +10,3 @@

var internals = {
const internals = {
delimiter: '&',

@@ -23,8 +25,8 @@ depth: 5,

var obj = {};
var parts = str.split(options.delimiter, options.parameterLimit === Infinity ? undefined : options.parameterLimit);
const obj = {};
const 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;
for (let i = 0; i < parts.length; ++i) {
const part = parts[i];
const pos = part.indexOf(']=') === -1 ? part.indexOf('=') : part.indexOf(']=') + 1;

@@ -39,4 +41,4 @@ if (pos === -1) {

else {
var key = Utils.decode(part.slice(0, pos));
var val = Utils.decode(part.slice(pos + 1));
const key = Utils.decode(part.slice(0, pos));
const val = Utils.decode(part.slice(pos + 1));

@@ -62,5 +64,5 @@ if (!Object.prototype.hasOwnProperty.call(obj, key)) {

var root = chain.shift();
const root = chain.shift();
var obj;
let obj;
if (root === '[]') {

@@ -72,5 +74,5 @@ obj = [];

obj = options.plainObjects ? Object.create(null) : {};
var cleanRoot = root[0] === '[' && root[root.length - 1] === ']' ? root.slice(1, root.length - 1) : root;
var index = parseInt(cleanRoot, 10);
var indexString = '' + index;
const cleanRoot = root[0] === '[' && root[root.length - 1] === ']' ? root.slice(1, root.length - 1) : root;
const index = parseInt(cleanRoot, 10);
const indexString = '' + index;
if (!isNaN(index) &&

@@ -109,12 +111,12 @@ root !== cleanRoot &&

var parent = /^([^\[\]]*)/;
var child = /(\[[^\[\]]*\])/g;
const parent = /^([^\[\]]*)/;
const child = /(\[[^\[\]]*\])/g;
// Get the parent
var segment = parent.exec(key);
let segment = parent.exec(key);
// Stash the parent if it exists
var keys = [];
const keys = [];
if (segment[1]) {

@@ -136,3 +138,3 @@ // If we aren't using plain objects, optionally prefix keys

var i = 0;
let i = 0;
while ((segment = child.exec(key)) !== null && i < options.depth) {

@@ -181,11 +183,11 @@

var tempObj = typeof str === 'string' ? internals.parseValues(str, options) : str;
var obj = options.plainObjects ? Object.create(null) : {};
const tempObj = typeof str === 'string' ? internals.parseValues(str, options) : str;
let obj = options.plainObjects ? Object.create(null) : {};
// 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);
const keys = Object.keys(tempObj);
for (let i = 0; i < keys.length; ++i) {
const key = keys[i];
const newObj = internals.parseKeys(key, tempObj[key], options);
obj = Utils.merge(obj, newObj, options);

@@ -192,0 +194,0 @@ }

@@ -0,4 +1,6 @@

'use strict';
// Load modules
var Utils = require('./utils');
const Utils = require('./utils');

@@ -8,3 +10,3 @@

var internals = {
const internals = {
delimiter: '&',

@@ -60,3 +62,3 @@ arrayPrefixGenerators: {

var values = [];
let values = [];

@@ -67,12 +69,13 @@ if (typeof obj === 'undefined') {

var objKeys;
let objKeys;
if (Array.isArray(filter)) {
objKeys = filter;
} else {
var keys = Object.keys(obj);
}
else {
const keys = Object.keys(obj);
objKeys = sort ? keys.sort(sort) : keys;
}
for (var i = 0, il = objKeys.length; i < il; ++i) {
var key = objKeys[i];
for (let i = 0; i < objKeys.length; ++i) {
const key = objKeys[i];

@@ -100,9 +103,9 @@ if (skipNulls &&

options = options || {};
var delimiter = typeof options.delimiter === 'undefined' ? internals.delimiter : options.delimiter;
var strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : internals.strictNullHandling;
var skipNulls = typeof options.skipNulls === 'boolean' ? options.skipNulls : internals.skipNulls;
var encode = typeof options.encode === 'boolean' ? options.encode : internals.encode;
var sort = typeof options.sort === 'function' ? options.sort : null;
var objKeys;
var filter;
const delimiter = typeof options.delimiter === 'undefined' ? internals.delimiter : options.delimiter;
const strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : internals.strictNullHandling;
const skipNulls = typeof options.skipNulls === 'boolean' ? options.skipNulls : internals.skipNulls;
const encode = typeof options.encode === 'boolean' ? options.encode : internals.encode;
const sort = typeof options.sort === 'function' ? options.sort : null;
let objKeys;
let filter;
if (typeof options.filter === 'function') {

@@ -116,3 +119,3 @@ filter = options.filter;

var keys = [];
let keys = [];

@@ -125,3 +128,3 @@ if (typeof obj !== 'object' ||

var arrayFormat;
let arrayFormat;
if (options.arrayFormat in internals.arrayPrefixGenerators) {

@@ -137,3 +140,3 @@ arrayFormat = options.arrayFormat;

var generateArrayPrefix = internals.arrayPrefixGenerators[arrayFormat];
const generateArrayPrefix = internals.arrayPrefixGenerators[arrayFormat];

@@ -148,4 +151,4 @@ if (!objKeys) {

for (var i = 0, il = objKeys.length; i < il; ++i) {
var key = objKeys[i];
for (let i = 0; i < objKeys.length; ++i) {
const key = objKeys[i];

@@ -152,0 +155,0 @@ if (skipNulls &&

@@ -0,1 +1,3 @@

'use strict';
// Load modules

@@ -6,15 +8,21 @@

var internals = {};
internals.hexTable = new Array(256);
for (var h = 0; h < 256; ++h) {
internals.hexTable[h] = '%' + ((h < 16 ? '0' : '') + h.toString(16)).toUpperCase();
}
const internals = {};
internals.hexTable = function () {
const array = new Array(256);
for (let i = 0; i < 256; ++i) {
array[i] = '%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase();
}
return array;
}();
exports.arrayToObject = function (source, options) {
var obj = options.plainObjects ? Object.create(null) : {};
for (var i = 0, il = source.length; i < il; ++i) {
const obj = options.plainObjects ? Object.create(null) : {};
for (let i = 0; i < source.length; ++i) {
if (typeof source[i] !== 'undefined') {
obj[i] = source[i];

@@ -59,6 +67,6 @@ }

var keys = Object.keys(source);
for (var k = 0, kl = keys.length; k < kl; ++k) {
var key = keys[k];
var value = source[key];
const keys = Object.keys(source);
for (let i = 0; i < keys.length; ++i) {
const key = keys[i];
const value = source[key];

@@ -81,3 +89,4 @@ if (!Object.prototype.hasOwnProperty.call(target, key)) {

return decodeURIComponent(str.replace(/\+/g, ' '));
} catch (e) {
}
catch (e) {
return str;

@@ -99,5 +108,5 @@ }

var out = '';
for (var i = 0, il = str.length; i < il; ++i) {
var c = str.charCodeAt(i);
let out = '';
for (let i = 0; i < str.length; ++i) {
let c = str.charCodeAt(i);

@@ -112,3 +121,3 @@ if (c === 0x2D || // -

out += str[i];
out = out + str[i];
continue;

@@ -118,3 +127,3 @@ }

if (c < 0x80) {
out += internals.hexTable[c];
out = out + internals.hexTable[c];
continue;

@@ -124,3 +133,3 @@ }

if (c < 0x800) {
out += internals.hexTable[0xC0 | (c >> 6)] + internals.hexTable[0x80 | (c & 0x3F)];
out = out + (internals.hexTable[0xC0 | (c >> 6)] + internals.hexTable[0x80 | (c & 0x3F)]);
continue;

@@ -130,3 +139,3 @@ }

if (c < 0xD800 || c >= 0xE000) {
out += internals.hexTable[0xE0 | (c >> 12)] + internals.hexTable[0x80 | ((c >> 6) & 0x3F)] + internals.hexTable[0x80 | (c & 0x3F)];
out = out + (internals.hexTable[0xE0 | (c >> 12)] + internals.hexTable[0x80 | ((c >> 6) & 0x3F)] + internals.hexTable[0x80 | (c & 0x3F)]);
continue;

@@ -137,3 +146,3 @@ }

c = 0x10000 + (((c & 0x3FF) << 10) | (str.charCodeAt(i) & 0x3FF));
out += internals.hexTable[0xF0 | (c >> 18)] + internals.hexTable[0x80 | ((c >> 12) & 0x3F)] + internals.hexTable[0x80 | ((c >> 6) & 0x3F)] + internals.hexTable[0x80 | (c & 0x3F)];
out = out + (internals.hexTable[0xF0 | (c >> 18)] + internals.hexTable[0x80 | ((c >> 12) & 0x3F)] + internals.hexTable[0x80 | ((c >> 6) & 0x3F)] + internals.hexTable[0x80 | (c & 0x3F)]);
}

@@ -153,3 +162,3 @@

refs = refs || [];
var lookup = refs.indexOf(obj);
const lookup = refs.indexOf(obj);
if (lookup !== -1) {

@@ -162,5 +171,5 @@ return refs[lookup];

if (Array.isArray(obj)) {
var compacted = [];
const compacted = [];
for (var i = 0, il = obj.length; i < il; ++i) {
for (let i = 0; i < obj.length; ++i) {
if (typeof obj[i] !== 'undefined') {

@@ -174,5 +183,5 @@ compacted.push(obj[i]);

var keys = Object.keys(obj);
for (i = 0, il = keys.length; i < il; ++i) {
var key = keys[i];
const keys = Object.keys(obj);
for (let i = 0; i < keys.length; ++i) {
const key = keys[i];
obj[key] = exports.compact(obj[key], refs);

@@ -179,0 +188,0 @@ }

@@ -5,3 +5,3 @@ {

"homepage": "https://github.com/hapijs/qs",
"version": "5.2.0",
"version": "6.0.0",
"repository": {

@@ -16,8 +16,8 @@ "type": "git",

],
"engines": ">=0.10.40",
"engines": ">=4.0.0",
"dependencies": {},
"devDependencies": {
"browserify": "^10.2.1",
"code": "1.x.x",
"lab": "5.x.x"
"code": "2.x.x",
"lab": "7.x.x"
},

@@ -24,0 +24,0 @@ "scripts": {

@@ -0,7 +1,9 @@

'use strict';
/* eslint no-extend-native:0 */
// Load modules
var Code = require('code');
var Lab = require('lab');
var Qs = require('../');
const Code = require('code');
const Lab = require('lab');
const Qs = require('../');

@@ -11,3 +13,3 @@

var internals = {};
const internals = {};

@@ -17,11 +19,11 @@

var lab = exports.lab = Lab.script();
var expect = Code.expect;
var describe = lab.experiment;
var it = lab.test;
const lab = exports.lab = Lab.script();
const expect = Code.expect;
const describe = lab.experiment;
const it = lab.test;
describe('parse()', function () {
describe('parse()', () => {
it('parses a simple string', function (done) {
it('parses a simple string', (done) => {

@@ -34,3 +36,3 @@ expect(Qs.parse('0=foo')).to.deep.equal({ '0': 'foo' });

expect(Qs.parse('foo', { strictNullHandling: true })).to.deep.equal({ foo: null });
expect(Qs.parse('foo' )).to.deep.equal({ foo: '' });
expect(Qs.parse('foo')).to.deep.equal({ foo: '' });
expect(Qs.parse('foo=')).to.deep.equal({ foo: '' });

@@ -53,3 +55,3 @@ expect(Qs.parse('foo=bar')).to.deep.equal({ foo: 'bar' });

it('allows enabling dot notation', function (done) {
it('allows enabling dot notation', (done) => {

@@ -61,3 +63,3 @@ expect(Qs.parse('a.b=c')).to.deep.equal({ 'a.b': 'c' });

it('parses a single nested string', function (done) {
it('parses a single nested string', (done) => {

@@ -68,3 +70,3 @@ expect(Qs.parse('a[b]=c')).to.deep.equal({ a: { b: 'c' } });

it('parses a double nested string', function (done) {
it('parses a double nested string', (done) => {

@@ -75,3 +77,3 @@ expect(Qs.parse('a[b][c]=d')).to.deep.equal({ a: { b: { c: 'd' } } });

it('defaults to a depth of 5', function (done) {
it('defaults to a depth of 5', (done) => {

@@ -82,3 +84,3 @@ expect(Qs.parse('a[b][c][d][e][f][g][h]=i')).to.deep.equal({ a: { b: { c: { d: { e: { f: { '[g][h]': 'i' } } } } } } });

it('only parses one level when depth = 1', function (done) {
it('only parses one level when depth = 1', (done) => {

@@ -90,3 +92,3 @@ expect(Qs.parse('a[b][c]=d', { depth: 1 })).to.deep.equal({ a: { b: { '[c]': 'd' } } });

it('parses a simple array', function (done) {
it('parses a simple array', (done) => {

@@ -97,3 +99,3 @@ expect(Qs.parse('a=b&a=c')).to.deep.equal({ a: ['b', 'c'] });

it('parses an explicit array', function (done) {
it('parses an explicit array', (done) => {

@@ -106,3 +108,3 @@ expect(Qs.parse('a[]=b')).to.deep.equal({ a: ['b'] });

it('parses a mix of simple and explicit arrays', function (done) {
it('parses a mix of simple and explicit arrays', (done) => {

@@ -118,3 +120,3 @@ expect(Qs.parse('a=b&a[]=c')).to.deep.equal({ a: ['b', 'c'] });

it('parses a nested array', function (done) {
it('parses a nested array', (done) => {

@@ -126,3 +128,3 @@ expect(Qs.parse('a[b][]=c&a[b][]=d')).to.deep.equal({ a: { b: ['c', 'd'] } });

it('allows to specify array indices', function (done) {
it('allows to specify array indices', (done) => {

@@ -135,3 +137,3 @@ expect(Qs.parse('a[1]=c&a[0]=b&a[2]=d')).to.deep.equal({ a: ['b', 'c', 'd'] });

it('limits specific array indices to 20', function (done) {
it('limits specific array indices to 20', (done) => {

@@ -143,3 +145,3 @@ expect(Qs.parse('a[20]=a')).to.deep.equal({ a: ['a'] });

it('supports keys that begin with a number', function (done) {
it('supports keys that begin with a number', (done) => {

@@ -150,3 +152,3 @@ expect(Qs.parse('a[12b]=c')).to.deep.equal({ a: { '12b': 'c' } });

it('supports encoded = signs', function (done) {
it('supports encoded = signs', (done) => {

@@ -157,3 +159,3 @@ expect(Qs.parse('he%3Dllo=th%3Dere')).to.deep.equal({ 'he=llo': 'th=ere' });

it('is ok with url encoded strings', function (done) {
it('is ok with url encoded strings', (done) => {

@@ -165,3 +167,3 @@ expect(Qs.parse('a[b%20c]=d')).to.deep.equal({ a: { 'b c': 'd' } });

it('allows brackets in the value', function (done) {
it('allows brackets in the value', (done) => {

@@ -173,3 +175,3 @@ expect(Qs.parse('pets=["tobi"]')).to.deep.equal({ pets: '["tobi"]' });

it('allows empty values', function (done) {
it('allows empty values', (done) => {

@@ -182,3 +184,3 @@ expect(Qs.parse('')).to.deep.equal({});

it('transforms arrays to objects', function (done) {
it('transforms arrays to objects', (done) => {

@@ -196,3 +198,3 @@ expect(Qs.parse('foo[0]=bar&foo[bad]=baz')).to.deep.equal({ foo: { '0': 'bar', bad: 'baz' } });

it('transforms arrays to objects (dot notation)', function (done) {
it('transforms arrays to objects (dot notation)', (done) => {

@@ -212,3 +214,3 @@ expect(Qs.parse('foo[0].baz=bar&fool.bad=baz', { allowDots: true })).to.deep.equal({ foo: [{ baz: 'bar' }], fool: { bad: 'baz' } });

it('can add keys to objects', function (done) {
it('can add keys to objects', (done) => {

@@ -219,3 +221,3 @@ expect(Qs.parse('a[b]=c&a=d')).to.deep.equal({ a: { b: 'c', d: true } });

it('correctly prunes undefined values when converting an array to an object', function (done) {
it('correctly prunes undefined values when converting an array to an object', (done) => {

@@ -226,3 +228,3 @@ expect(Qs.parse('a[2]=b&a[99999999]=c')).to.deep.equal({ a: { '2': 'b', '99999999': 'c' } });

it('supports malformed uri characters', function (done) {
it('supports malformed uri characters', (done) => {

@@ -235,3 +237,3 @@ expect(Qs.parse('{%:%}', { strictNullHandling: true })).to.deep.equal({ '{%:%}': null });

it('doesn\'t produce empty keys', function (done) {
it('doesn\'t produce empty keys', (done) => {

@@ -242,3 +244,3 @@ expect(Qs.parse('_r=1&')).to.deep.equal({ '_r': '1' });

it('cannot access Object prototype', function (done) {
it('cannot access Object prototype', (done) => {

@@ -251,3 +253,3 @@ Qs.parse('constructor[prototype][bad]=bad');

it('parses arrays of objects', function (done) {
it('parses arrays of objects', (done) => {

@@ -259,3 +261,3 @@ expect(Qs.parse('a[][b]=c')).to.deep.equal({ a: [{ b: 'c' }] });

it('allows for empty strings in arrays', function (done) {
it('allows for empty strings in arrays', (done) => {

@@ -269,3 +271,3 @@ expect(Qs.parse('a[]=b&a[]=&a[]=c')).to.deep.equal({ a: ['b', '', 'c'] });

it('compacts sparse arrays', function (done) {
it('compacts sparse arrays', (done) => {

@@ -276,3 +278,3 @@ expect(Qs.parse('a[10]=1&a[2]=2')).to.deep.equal({ a: ['2', '1'] });

it('parses semi-parsed strings', function (done) {
it('parses semi-parsed strings', (done) => {

@@ -284,5 +286,5 @@ expect(Qs.parse({ 'a[b]': 'c' })).to.deep.equal({ a: { b: 'c' } });

it('parses buffers correctly', function (done) {
it('parses buffers correctly', (done) => {
var b = new Buffer('test');
const b = new Buffer('test');
expect(Qs.parse({ a: b })).to.deep.equal({ a: b });

@@ -292,3 +294,3 @@ done();

it('continues parsing when no parent is found', function (done) {
it('continues parsing when no parent is found', (done) => {

@@ -301,10 +303,10 @@ expect(Qs.parse('[]=&a=b')).to.deep.equal({ '0': '', a: 'b' });

it('does not error when parsing a very long array', function (done) {
it('does not error when parsing a very long array', (done) => {
var str = 'a[]=a';
let str = 'a[]=a';
while (Buffer.byteLength(str) < 128 * 1024) {
str += '&' + str;
str = str + '&' + str;
}
expect(function () {
expect(() => {

@@ -317,3 +319,3 @@ Qs.parse(str);

it('should not throw when a native prototype has an enumerable property', { parallel: false }, function (done) {
it('should not throw when a native prototype has an enumerable property', { parallel: false }, (done) => {

@@ -331,3 +333,3 @@ Object.prototype.crash = '';

it('parses a string with an alternative string delimiter', function (done) {
it('parses a string with an alternative string delimiter', (done) => {

@@ -338,3 +340,3 @@ expect(Qs.parse('a=b;c=d', { delimiter: ';' })).to.deep.equal({ a: 'b', c: 'd' });

it('parses a string with an alternative RegExp delimiter', function (done) {
it('parses a string with an alternative RegExp delimiter', (done) => {

@@ -345,3 +347,3 @@ expect(Qs.parse('a=b; c=d', { delimiter: /[;,] */ })).to.deep.equal({ a: 'b', c: 'd' });

it('does not use non-splittable objects as delimiters', function (done) {
it('does not use non-splittable objects as delimiters', (done) => {

@@ -352,3 +354,3 @@ expect(Qs.parse('a=b&c=d', { delimiter: true })).to.deep.equal({ a: 'b', c: 'd' });

it('allows overriding parameter limit', function (done) {
it('allows overriding parameter limit', (done) => {

@@ -359,3 +361,3 @@ expect(Qs.parse('a=b&c=d', { parameterLimit: 1 })).to.deep.equal({ a: 'b' });

it('allows setting the parameter limit to Infinity', function (done) {
it('allows setting the parameter limit to Infinity', (done) => {

@@ -366,3 +368,3 @@ expect(Qs.parse('a=b&c=d', { parameterLimit: Infinity })).to.deep.equal({ a: 'b', c: 'd' });

it('allows overriding array limit', function (done) {
it('allows overriding array limit', (done) => {

@@ -375,3 +377,3 @@ expect(Qs.parse('a[0]=b', { arrayLimit: -1 })).to.deep.equal({ a: { '0': 'b' } });

it('allows disabling array parsing', function (done) {
it('allows disabling array parsing', (done) => {

@@ -382,5 +384,5 @@ expect(Qs.parse('a[0]=b&a[1]=c', { parseArrays: false })).to.deep.equal({ a: { '0': 'b', '1': 'c' } });

it('parses an object', function (done) {
it('parses an object', (done) => {
var input = {
const input = {
'user[name]': { 'pop[bob]': 3 },

@@ -390,3 +392,3 @@ 'user[email]': null

var expected = {
const expected = {
'user': {

@@ -398,3 +400,3 @@ 'name': { 'pop[bob]': 3 },

var result = Qs.parse(input);
const result = Qs.parse(input);

@@ -405,5 +407,5 @@ expect(result).to.deep.equal(expected);

it('parses an object in dot notation', function (done) {
it('parses an object in dot notation', (done) => {
var input = {
const input = {
'user.name': { 'pop[bob]': 3 },

@@ -413,3 +415,3 @@ 'user.email.': null

var expected = {
const expected = {
'user': {

@@ -421,3 +423,3 @@ 'name': { 'pop[bob]': 3 },

var result = Qs.parse(input, { allowDots: true });
const result = Qs.parse(input, { allowDots: true });

@@ -428,5 +430,5 @@ expect(result).to.deep.equal(expected);

it('parses an object and not child values', function (done) {
it('parses an object and not child values', (done) => {
var input = {
const input = {
'user[name]': { 'pop[bob]': { 'test': 3 } },

@@ -436,3 +438,3 @@ 'user[email]': null

var expected = {
const expected = {
'user': {

@@ -444,3 +446,3 @@ 'name': { 'pop[bob]': { 'test': 3 } },

var result = Qs.parse(input);
const result = Qs.parse(input);

@@ -451,7 +453,7 @@ expect(result).to.deep.equal(expected);

it('does not blow up when Buffer global is missing', function (done) {
it('does not blow up when Buffer global is missing', (done) => {
var tempBuffer = global.Buffer;
const tempBuffer = global.Buffer;
delete global.Buffer;
var result = Qs.parse('a=b&c=d');
const result = Qs.parse('a=b&c=d');
global.Buffer = tempBuffer;

@@ -462,10 +464,10 @@ expect(result).to.deep.equal({ a: 'b', c: 'd' });

it('does not crash when parsing circular references', function (done) {
it('does not crash when parsing circular references', (done) => {
var a = {};
const a = {};
a.b = a;
var parsed;
let parsed;
expect(function () {
expect(() => {

@@ -482,9 +484,9 @@ parsed = Qs.parse({ 'foo[bar]': 'baz', 'foo[baz]': a });

it('parses plain objects correctly', function (done) {
it('parses plain objects correctly', (done) => {
var a = Object.create(null);
const a = Object.create(null);
a.b = 'c';
expect(Qs.parse(a)).to.deep.equal({ b: 'c' });
var result = Qs.parse({ a: a });
const result = Qs.parse({ a: a });
expect(result).to.contain('a');

@@ -495,5 +497,5 @@ expect(result.a).to.deep.equal(a);

it('parses dates correctly', function (done) {
it('parses dates correctly', (done) => {
var now = new Date();
const now = new Date();
expect(Qs.parse({ a: now })).to.deep.equal({ a: now });

@@ -503,5 +505,5 @@ done();

it('parses regular expressions correctly', function (done) {
it('parses regular expressions correctly', (done) => {
var re = /^test$/;
const re = /^test$/;
expect(Qs.parse({ a: re })).to.deep.equal({ a: re });

@@ -511,3 +513,3 @@ done();

it('can allow overwriting prototype properties', function (done) {
it('can allow overwriting prototype properties', (done) => {

@@ -519,5 +521,5 @@ expect(Qs.parse('a[hasOwnProperty]=b', { allowPrototypes: true })).to.deep.equal({ a: { hasOwnProperty: 'b' } }, { prototype: false });

it('can return plain objects', function (done) {
it('can return plain objects', (done) => {
var expected = Object.create(null);
const expected = Object.create(null);
expected.a = Object.create(null);

@@ -528,3 +530,3 @@ expected.a.b = 'c';

expect(Qs.parse(null, { plainObjects: true })).to.deep.equal(Object.create(null));
var expectedArray = Object.create(null);
const expectedArray = Object.create(null);
expectedArray.a = Object.create(null);

@@ -531,0 +533,0 @@ expectedArray.a['0'] = 'b';

@@ -0,7 +1,9 @@

'use strict';
/* eslint no-extend-native:0 */
// Load modules
var Code = require('code');
var Lab = require('lab');
var Qs = require('../');
const Code = require('code');
const Lab = require('lab');
const Qs = require('../');

@@ -11,3 +13,3 @@

var internals = {};
const internals = {};

@@ -17,11 +19,11 @@

var lab = exports.lab = Lab.script();
var expect = Code.expect;
var describe = lab.experiment;
var it = lab.test;
const lab = exports.lab = Lab.script();
const expect = Code.expect;
const describe = lab.experiment;
const it = lab.test;
describe('stringify()', function () {
describe('stringify()', () => {
it('stringifies a querystring object', function (done) {
it('stringifies a querystring object', (done) => {

@@ -39,3 +41,3 @@ expect(Qs.stringify({ a: 'b' })).to.equal('a=b');

it('stringifies a nested object', function (done) {
it('stringifies a nested object', (done) => {

@@ -47,3 +49,3 @@ expect(Qs.stringify({ a: { b: 'c' } })).to.equal('a%5Bb%5D=c');

it('stringifies an array value', function (done) {
it('stringifies an array value', (done) => {

@@ -54,3 +56,3 @@ expect(Qs.stringify({ a: ['b', 'c', 'd'] })).to.equal('a%5B0%5D=b&a%5B1%5D=c&a%5B2%5D=d');

it('omits nulls when asked', function (done) {
it('omits nulls when asked', (done) => {

@@ -62,3 +64,3 @@ expect(Qs.stringify({ a: 'b', c: null }, { skipNulls: true })).to.equal('a=b');

it('omits nested nulls when asked', function (done) {
it('omits nested nulls when asked', (done) => {

@@ -69,3 +71,3 @@ expect(Qs.stringify({ a: { b: 'c', d: null } }, { skipNulls: true })).to.equal('a%5Bb%5D=c');

it('omits array indices when asked', function (done) {
it('omits array indices when asked', (done) => {

@@ -76,3 +78,3 @@ expect(Qs.stringify({ a: ['b', 'c', 'd'] }, { indices: false })).to.equal('a=b&a=c&a=d');

it('stringifies a nested array value', function (done) {
it('stringifies a nested array value', (done) => {

@@ -83,3 +85,3 @@ expect(Qs.stringify({ a: { b: ['c', 'd'] } })).to.equal('a%5Bb%5D%5B0%5D=c&a%5Bb%5D%5B1%5D=d');

it('stringifies an object inside an array', function (done) {
it('stringifies an object inside an array', (done) => {

@@ -91,3 +93,3 @@ expect(Qs.stringify({ a: [{ b: 'c' }] })).to.equal('a%5B0%5D%5Bb%5D=c');

it('does not omit object keys when indices = false', function (done) {
it('does not omit object keys when indices = false', (done) => {

@@ -98,3 +100,3 @@ expect(Qs.stringify({ a: [{ b: 'c' }] }, { indices: false })).to.equal('a%5Bb%5D=c');

it('uses indices notation for arrays when indices=true', function (done) {
it('uses indices notation for arrays when indices=true', (done) => {

@@ -105,3 +107,3 @@ expect(Qs.stringify({ a: ['b', 'c'] }, { indices: true })).to.equal('a%5B0%5D=b&a%5B1%5D=c');

it('uses indices notation for arrays when no arrayFormat is specified', function (done) {
it('uses indices notation for arrays when no arrayFormat is specified', (done) => {

@@ -112,3 +114,3 @@ expect(Qs.stringify({ a: ['b', 'c'] })).to.equal('a%5B0%5D=b&a%5B1%5D=c');

it('uses indices notation for arrays when no arrayFormat=indices', function (done) {
it('uses indices notation for arrays when no arrayFormat=indices', (done) => {

@@ -119,3 +121,3 @@ expect(Qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'indices' })).to.equal('a%5B0%5D=b&a%5B1%5D=c');

it('uses repeat notation for arrays when no arrayFormat=repeat', function (done) {
it('uses repeat notation for arrays when no arrayFormat=repeat', (done) => {

@@ -126,3 +128,3 @@ expect(Qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'repeat' })).to.equal('a=b&a=c');

it('uses brackets notation for arrays when no arrayFormat=brackets', function (done) {
it('uses brackets notation for arrays when no arrayFormat=brackets', (done) => {

@@ -133,3 +135,3 @@ expect(Qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'brackets' })).to.equal('a%5B%5D=b&a%5B%5D=c');

it('stringifies a complicated object', function (done) {
it('stringifies a complicated object', (done) => {

@@ -140,3 +142,3 @@ expect(Qs.stringify({ a: { b: 'c', d: 'e' } })).to.equal('a%5Bb%5D=c&a%5Bd%5D=e');

it('stringifies an empty value', function (done) {
it('stringifies an empty value', (done) => {

@@ -156,5 +158,5 @@ expect(Qs.stringify({ a: '' })).to.equal('a=');

it('stringifies an empty object', function (done) {
it('stringifies an empty object', (done) => {
var obj = Object.create(null);
const obj = Object.create(null);
obj.a = 'b';

@@ -165,3 +167,3 @@ expect(Qs.stringify(obj)).to.equal('a=b');

it('returns an empty string for invalid input', function (done) {
it('returns an empty string for invalid input', (done) => {

@@ -175,5 +177,5 @@ expect(Qs.stringify(undefined)).to.equal('');

it('stringifies an object with an empty object as a child', function (done) {
it('stringifies an object with an empty object as a child', (done) => {
var obj = {
const obj = {
a: Object.create(null)

@@ -187,3 +189,3 @@ };

it('drops keys with a value of undefined', function (done) {
it('drops keys with a value of undefined', (done) => {

@@ -198,3 +200,3 @@ expect(Qs.stringify({ a: undefined })).to.equal('');

it('url encodes values', function (done) {
it('url encodes values', (done) => {

@@ -205,6 +207,6 @@ expect(Qs.stringify({ a: 'b c' })).to.equal('a=b%20c');

it('stringifies a date', function (done) {
it('stringifies a date', (done) => {
var now = new Date();
var str = 'a=' + encodeURIComponent(now.toISOString());
const now = new Date();
const str = 'a=' + encodeURIComponent(now.toISOString());
expect(Qs.stringify({ a: now })).to.equal(str);

@@ -214,3 +216,3 @@ done();

it('stringifies the weird object from qs', function (done) {
it('stringifies the weird object from qs', (done) => {

@@ -221,3 +223,3 @@ expect(Qs.stringify({ 'my weird field': '~q1!2"\'w$5&7/z8)?' })).to.equal('my%20weird%20field=~q1%212%22%27w%245%267%2Fz8%29%3F');

it('skips properties that are part of the object prototype', function (done) {
it('skips properties that are part of the object prototype', (done) => {

@@ -231,3 +233,3 @@ Object.prototype.crash = 'test';

it('stringifies boolean values', function (done) {
it('stringifies boolean values', (done) => {

@@ -241,3 +243,3 @@ expect(Qs.stringify({ a: true })).to.equal('a=true');

it('stringifies buffer values', function (done) {
it('stringifies buffer values', (done) => {

@@ -249,3 +251,3 @@ expect(Qs.stringify({ a: new Buffer('test') })).to.equal('a=test');

it('stringifies an object using an alternative delimiter', function (done) {
it('stringifies an object using an alternative delimiter', (done) => {

@@ -256,7 +258,7 @@ expect(Qs.stringify({ a: 'b', c: 'd' }, { delimiter: ';' })).to.equal('a=b;c=d');

it('doesn\'t blow up when Buffer global is missing', function (done) {
it('doesn\'t blow up when Buffer global is missing', (done) => {
var tempBuffer = global.Buffer;
const tempBuffer = global.Buffer;
delete global.Buffer;
var result = Qs.stringify({ a: 'b', c: 'd' });
const result = Qs.stringify({ a: 'b', c: 'd' });
global.Buffer = tempBuffer;

@@ -267,3 +269,3 @@ expect(result).to.equal('a=b&c=d');

it('selects properties when filter=array', function (done) {
it('selects properties when filter=array', (done) => {

@@ -277,7 +279,7 @@ expect(Qs.stringify({ a: 'b' }, { filter: ['a'] })).to.equal('a=b');

it('supports custom representations when filter=function', function (done) {
it('supports custom representations when filter=function', (done) => {
var calls = 0;
var obj = { a: 'b', c: 'd', e: { f: new Date(1257894000000) } };
var filterFunc = function (prefix, value) {
let calls = 0;
const obj = { a: 'b', c: 'd', e: { f: new Date(1257894000000) } };
const filterFunc = function (prefix, value) {

@@ -305,3 +307,3 @@ calls++;

it('can disable uri encoding', function (done) {
it('can disable uri encoding', (done) => {

@@ -314,13 +316,9 @@ expect(Qs.stringify({ a: 'b' }, { encode: false })).to.equal('a=b');

it('can sort the keys', function (done) {
it('can sort the keys', (done) => {
var sort = function alphabeticalSort (a, b) {
return a.localeCompare(b);
};
expect(Qs.stringify({ a: 'c', z: 'y', b : 'f' }, { sort : sort })).to.equal('a=c&b=f&z=y');
expect(Qs.stringify({ a: 'c', z: { j: 'a', i:'b' }, b : 'f' }, { sort : sort })).to.equal('a=c&b=f&z%5Bi%5D=b&z%5Bj%5D=a');
const sort = (a, b) => a.localeCompare(b);
expect(Qs.stringify({ a: 'c', z: 'y', b: 'f' }, { sort: sort })).to.equal('a=c&b=f&z=y');
expect(Qs.stringify({ a: 'c', z: { j: 'a', i: 'b' }, b: 'f' }, { sort: sort })).to.equal('a=c&b=f&z%5Bi%5D=b&z%5Bj%5D=a');
done();
});
});

@@ -0,6 +1,8 @@

'use strict';
// Load modules
var Code = require('code');
var Lab = require('lab');
var Utils = require('../lib/utils');
const Code = require('code');
const Lab = require('lab');
const Utils = require('../lib/utils');

@@ -10,3 +12,3 @@

var internals = {};
const internals = {};

@@ -16,11 +18,11 @@

var lab = exports.lab = Lab.script();
var expect = Code.expect;
var describe = lab.experiment;
var it = lab.test;
const lab = exports.lab = Lab.script();
const expect = Code.expect;
const describe = lab.experiment;
const it = lab.test;
describe('merge()', function () {
describe('merge()', () => {
it('can merge two objects with the same key', function (done) {
it('can merge two objects with the same key', (done) => {

@@ -27,0 +29,0 @@ expect(Utils.merge({ a: 'b' }, { a: 'c' })).to.deep.equal({ a: ['b', 'c'] });

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc