diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json index 72560b7477..c04376823a 100644 --- a/node_modules/.package-lock.json +++ b/node_modules/.package-lock.json @@ -4472,8 +4472,9 @@ } }, "node_modules/query-string": { - "version": "6.14.0", - "license": "MIT", + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/query-string/-/query-string-7.0.1.tgz", + "integrity": "sha512-uIw3iRvHnk9to1blJCG3BTc+Ro56CBowJXKmNNAm3RulvPBzWLRqKSiiDk+IplJhsydwtuNMHi8UGQFcCLVfkA==", "dependencies": { "decode-uri-component": "^0.2.0", "filter-obj": "^1.1.0", diff --git a/node_modules/query-string/index.d.ts b/node_modules/query-string/index.d.ts index b6d651b2bb..847336d468 100644 --- a/node_modules/query-string/index.d.ts +++ b/node_modules/query-string/index.d.ts @@ -45,6 +45,30 @@ export interface ParseOptions { //=> {foo: ['1', '2', '3']} ``` + - `bracket-separator`: Parse arrays (that are explicitly marked with brackets) with elements separated by a custom character: + + ``` + import queryString = require('query-string'); + + queryString.parse('foo[]', {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'}); + //=> {foo: []} + + queryString.parse('foo[]=', {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'}); + //=> {foo: ['']} + + queryString.parse('foo[]=1', {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'}); + //=> {foo: ['1']} + + queryString.parse('foo[]=1|2|3', {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'}); + //=> {foo: ['1', '2', '3']} + + queryString.parse('foo[]=1||3|||6', {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'}); + //=> {foo: ['1', '', 3, '', '', '6']} + + queryString.parse('foo[]=1|2|3&bar=fluffy&baz[]=4', {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'}); + //=> {foo: ['1', '2', '3'], bar: 'fluffy', baz:['4']} + ``` + - `none`: Parse arrays with elements using duplicate keys: ``` @@ -54,7 +78,7 @@ export interface ParseOptions { //=> {foo: ['1', '2', '3']} ``` */ - readonly arrayFormat?: 'bracket' | 'index' | 'comma' | 'separator' | 'none'; + readonly arrayFormat?: 'bracket' | 'index' | 'comma' | 'separator' | 'bracket-separator' | 'none'; /** The character used to separate array elements when using `{arrayFormat: 'separator'}`. @@ -229,9 +253,14 @@ export interface StringifyOptions { queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'comma'}); //=> 'foo=1,2,3' + + queryString.stringify({foo: [1, null, '']}, {arrayFormat: 'comma'}); + //=> 'foo=1,,' + // Note that typing information for null values is lost + // and `.parse('foo=1,,')` would return `{foo: [1, '', '']}`. ``` - - `separator`: Serialize arrays by separating elements with character: + - `separator`: Serialize arrays by separating elements with character: ``` import queryString = require('query-string'); @@ -240,6 +269,33 @@ export interface StringifyOptions { //=> 'foo=1|2|3' ``` + - `bracket-separator`: Serialize arrays by explicitly post-fixing array names with brackets and separating elements with a custom character: + + ``` + import queryString = require('query-string'); + + queryString.stringify({foo: []}, {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'}); + //=> 'foo[]' + + queryString.stringify({foo: ['']}, {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'}); + //=> 'foo[]=' + + queryString.stringify({foo: [1]}, {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'}); + //=> 'foo[]=1' + + queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'}); + //=> 'foo[]=1|2|3' + + queryString.stringify({foo: [1, '', 3, null, null, 6]}, {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'}); + //=> 'foo[]=1||3|||6' + + queryString.stringify({foo: [1, '', 3, null, null, 6]}, {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|', skipNull: true}); + //=> 'foo[]=1||3|6' + + queryString.stringify({foo: [1, 2, 3], bar: 'fluffy', baz: [4]}, {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'}); + //=> 'foo[]=1|2|3&bar=fluffy&baz[]=4' + ``` + - `none`: Serialize arrays by using duplicate keys: ``` @@ -249,7 +305,7 @@ export interface StringifyOptions { //=> 'foo=1&foo=2&foo=3' ``` */ - readonly arrayFormat?: 'bracket' | 'index' | 'comma' | 'separator' | 'none'; + readonly arrayFormat?: 'bracket' | 'index' | 'comma' | 'separator' | 'bracket-separator' | 'none'; /** The character used to separate array elements when using `{arrayFormat: 'separator'}`. @@ -372,7 +428,7 @@ export interface UrlObject { /** Overrides queries in the `url` property. */ - readonly query: StringifiableRecord; + readonly query?: StringifiableRecord; /** Overrides the fragment identifier in the `url` property. diff --git a/node_modules/query-string/index.js b/node_modules/query-string/index.js index 423b9d6bce..cc57637327 100644 --- a/node_modules/query-string/index.js +++ b/node_modules/query-string/index.js @@ -6,6 +6,8 @@ const filterObject = require('filter-obj'); const isNullOrUndefined = value => value === null || value === undefined; +const encodeFragmentIdentifier = Symbol('encodeFragmentIdentifier'); + function encoderForArrayFormat(options) { switch (options.arrayFormat) { case 'index': @@ -49,17 +51,30 @@ function encoderForArrayFormat(options) { case 'comma': case 'separator': + case 'bracket-separator': { + const keyValueSep = options.arrayFormat === 'bracket-separator' ? + '[]=' : + '='; + return key => (result, value) => { - if (value === null || value === undefined || value.length === 0) { + if ( + value === undefined || + (options.skipNull && value === null) || + (options.skipEmptyString && value === '') + ) { return result; } + // Translate null to an empty string so that it doesn't serialize as 'null' + value = value === null ? '' : value; + if (result.length === 0) { - return [[encode(key, options), '=', encode(value, options)].join('')]; + return [[encode(key, options), keyValueSep, encode(value, options)].join('')]; } return [[result, encode(value, options)].join(options.arrayFormatSeparator)]; }; + } default: return key => (result, value) => { @@ -130,6 +145,28 @@ function parserForArrayFormat(options) { accumulator[key] = newValue; }; + case 'bracket-separator': + return (key, value, accumulator) => { + const isArray = /(\[\])$/.test(key); + key = key.replace(/\[\]$/, ''); + + if (!isArray) { + accumulator[key] = value ? decode(value, options) : value; + return; + } + + const arrayValue = value === null ? + [] : + value.split(options.arrayFormatSeparator).map(item => decode(item, options)); + + if (accumulator[key] === undefined) { + accumulator[key] = arrayValue; + return; + } + + accumulator[key] = [].concat(accumulator[key], arrayValue); + }; + default: return (key, value, accumulator) => { if (accumulator[key] === undefined) { @@ -253,7 +290,7 @@ function parse(query, options) { // Missing `=` should be `null`: // http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters - value = value === undefined ? null : ['comma', 'separator'].includes(options.arrayFormat) ? value : decode(value, options); + value = value === undefined ? null : ['comma', 'separator', 'bracket-separator'].includes(options.arrayFormat) ? value : decode(value, options); formatter(decode(key, options), value, ret); } @@ -335,6 +372,10 @@ exports.stringify = (object, options) => { } if (Array.isArray(value)) { + if (value.length === 0 && options.arrayFormat === 'bracket-separator') { + return encode(key, options) + '[]'; + } + return value .reduce(formatter(key), []) .join('&'); @@ -363,7 +404,8 @@ exports.parseUrl = (url, options) => { exports.stringifyUrl = (object, options) => { options = Object.assign({ encode: true, - strict: true + strict: true, + [encodeFragmentIdentifier]: true }, options); const url = removeHash(object.url).split('?')[0] || ''; @@ -378,7 +420,7 @@ exports.stringifyUrl = (object, options) => { let hash = getHash(object.url); if (object.fragmentIdentifier) { - hash = `#${encode(object.fragmentIdentifier, options)}`; + hash = `#${options[encodeFragmentIdentifier] ? encode(object.fragmentIdentifier, options) : object.fragmentIdentifier}`; } return `${url}${queryString}${hash}`; @@ -386,7 +428,8 @@ exports.stringifyUrl = (object, options) => { exports.pick = (input, filter, options) => { options = Object.assign({ - parseFragmentIdentifier: true + parseFragmentIdentifier: true, + [encodeFragmentIdentifier]: false }, options); const {url, query, fragmentIdentifier} = exports.parseUrl(input, options); diff --git a/node_modules/query-string/package.json b/node_modules/query-string/package.json index cf379b4442..6c280ddb89 100644 --- a/node_modules/query-string/package.json +++ b/node_modules/query-string/package.json @@ -1,6 +1,6 @@ { "name": "query-string", - "version": "6.14.0", + "version": "7.0.1", "description": "Parse and stringify URL query strings", "license": "MIT", "repository": "sindresorhus/query-string", diff --git a/node_modules/query-string/readme.md b/node_modules/query-string/readme.md index 280972e398..3af49af9dc 100644 --- a/node_modules/query-string/readme.md +++ b/node_modules/query-string/readme.md @@ -17,7 +17,40 @@

- + + +
+
+
+ +
+ Doppler +
+ All your environment variables, in one place +
+ Stop struggling with scattered API keys, hacking together home-brewed tools, +
+ and avoiding access controls. Keep your team and servers in sync with Doppler. +
+
+
+ +
+ Strapi +
+ Strapi is the leading open-source headless CMS. +
+ It’s 100% JavaScript, fully customizable, and developer-first. +
+
+
+ +
+ OSS Capital +
+
+ Founded in 2018, OSS Capital is the first and only venture capital platform focused
exclusively on supporting early-stage COSS (commercial open source) startup founders.
+

@@ -32,7 +65,9 @@ $ npm install query-string ``` -This module targets Node.js 6 or later and the latest version of Chrome, Firefox, and Safari. If you want support for older browsers, or, if your project is using create-react-app v1, use version 5: `npm install query-string@5`. +**Not `npm install querystring`!!!!!** + +This module targets Node.js 6 or later and the latest version of Chrome, Firefox, and Safari. ## Usage @@ -125,6 +160,30 @@ queryString.parse('foo=1|2|3', {arrayFormat: 'separator', arrayFormatSeparator: //=> {foo: ['1', '2', '3']} ``` +- `'bracket-separator'`: Parse arrays (that are explicitly marked with brackets) with elements separated by a custom character: + +```js +const queryString = require('query-string'); + +queryString.parse('foo[]', {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'}); +//=> {foo: []} + +queryString.parse('foo[]=', {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'}); +//=> {foo: ['']} + +queryString.parse('foo[]=1', {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'}); +//=> {foo: ['1']} + +queryString.parse('foo[]=1|2|3', {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'}); +//=> {foo: ['1', '2', '3']} + +queryString.parse('foo[]=1||3|||6', {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'}); +//=> {foo: ['1', '', 3, '', '', '6']} + +queryString.parse('foo[]=1|2|3&bar=fluffy&baz[]=4', {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'}); +//=> {foo: ['1', '2', '3'], bar: 'fluffy', baz:['4']} +``` + - `'none'`: Parse arrays with elements using duplicate keys: ```js @@ -228,6 +287,47 @@ const queryString = require('query-string'); queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'comma'}); //=> 'foo=1,2,3' + +queryString.stringify({foo: [1, null, '']}, {arrayFormat: 'comma'}); +//=> 'foo=1,,' +// Note that typing information for null values is lost +// and `.parse('foo=1,,')` would return `{foo: [1, '', '']}`. +``` + +- `'separator'`: Serialize arrays by separating elements with a custom character: + +```js +const queryString = require('query-string'); + +queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'separator', arrayFormatSeparator: '|'}); +//=> 'foo=1|2|3' +``` + +- `'bracket-separator'`: Serialize arrays by explicitly post-fixing array names with brackets and separating elements with a custom character: + +```js +const queryString = require('query-string'); + +queryString.stringify({foo: []}, {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'}); +//=> 'foo[]' + +queryString.stringify({foo: ['']}, {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'}); +//=> 'foo[]=' + +queryString.stringify({foo: [1]}, {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'}); +//=> 'foo[]=1' + +queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'}); +//=> 'foo[]=1|2|3' + +queryString.stringify({foo: [1, '', 3, null, null, 6]}, {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'}); +//=> 'foo[]=1||3|||6' + +queryString.stringify({foo: [1, '', 3, null, null, 6]}, {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|', skipNull: true}); +//=> 'foo[]=1||3|6' + +queryString.stringify({foo: [1, 2, 3], bar: 'fluffy', baz: [4]}, {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'}); +//=> 'foo[]=1|2|3&bar=fluffy&baz[]=4' ``` - `'none'`: Serialize arrays by using duplicate keys: @@ -520,6 +620,12 @@ queryString.stringify({foo: undefined}); //=> '' ``` +## FAQ + +### Why is it parsing `+` as a space? + +See [this answer](https://github.com/sindresorhus/query-string/issues/305). + ## query-string for enterprise Available as part of the Tidelift Subscription. diff --git a/package-lock.json b/package-lock.json index 07c451e7a5..cf79705e42 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,7 +31,7 @@ "long": "^4.0.0", "md5": "^2.2.1", "path": "^0.12.7", - "query-string": "^6.14.0", + "query-string": "^7.0.1", "semver": "^7.3.2", "uuid": "^8.3.0", "zlib": "^1.0.5" @@ -4526,8 +4526,9 @@ } }, "node_modules/query-string": { - "version": "6.14.0", - "license": "MIT", + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/query-string/-/query-string-7.0.1.tgz", + "integrity": "sha512-uIw3iRvHnk9to1blJCG3BTc+Ro56CBowJXKmNNAm3RulvPBzWLRqKSiiDk+IplJhsydwtuNMHi8UGQFcCLVfkA==", "dependencies": { "decode-uri-component": "^0.2.0", "filter-obj": "^1.1.0", @@ -8904,7 +8905,9 @@ } }, "query-string": { - "version": "6.14.0", + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/query-string/-/query-string-7.0.1.tgz", + "integrity": "sha512-uIw3iRvHnk9to1blJCG3BTc+Ro56CBowJXKmNNAm3RulvPBzWLRqKSiiDk+IplJhsydwtuNMHi8UGQFcCLVfkA==", "requires": { "decode-uri-component": "^0.2.0", "filter-obj": "^1.1.0", diff --git a/package.json b/package.json index d1ba69897e..fb6b61de30 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "long": "^4.0.0", "md5": "^2.2.1", "path": "^0.12.7", - "query-string": "^6.14.0", + "query-string": "^7.0.1", "semver": "^7.3.2", "uuid": "^8.3.0", "zlib": "^1.0.5"