qs 6.15.0 → 6.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.md +1 -1
- package/dist/qs.js +15 -15
- package/eslint.config.mjs +1 -0
- package/lib/parse.js +54 -24
- package/lib/stringify.js +11 -4
- package/package.json +3 -3
- package/test/parse.js +135 -0
- package/test/stringify.js +138 -0
- package/test/utils.js +31 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
## **6.15.2**
|
|
2
|
+
- [Fix] `stringify`: skip null/undefined entries in `arrayFormat: 'comma'` + `encodeValuesOnly` instead of crashing in `encoder`
|
|
3
|
+
- [Fix] `stringify`: use configured `delimiter` after `charsetSentinel` (#555)
|
|
4
|
+
- [Fix] `stringify`: apply `formatter` to encoded key under `strictNullHandling` (#554)
|
|
5
|
+
- [Fix] `stringify`: skip null/undefined filter-array entries instead of crashing in `encoder` (#551)
|
|
6
|
+
- [Fix] `parse`: handle nested bracket groups and add regression tests (#530)
|
|
7
|
+
- [readme] fix grammar (#550)
|
|
8
|
+
- [Dev Deps] update `@ljharb/eslint-config`
|
|
9
|
+
- [Tests] add regression tests for keys containing percent-encoded bracket text
|
|
10
|
+
|
|
11
|
+
## **6.15.1**
|
|
12
|
+
- [Fix] `parse`: `parameterLimit: Infinity` with `throwOnLimitExceeded: true` silently drops all parameters
|
|
13
|
+
- [Deps] update `@ljharb/eslint-config`
|
|
14
|
+
- [Dev Deps] update `@ljharb/eslint-config`, `iconv-lite`
|
|
15
|
+
- [Tests] increase coverage
|
|
16
|
+
|
|
1
17
|
## **6.15.0**
|
|
2
18
|
- [New] `parse`: add `strictMerge` option to wrap object/primitive conflicts in an array (#425, #122)
|
|
3
19
|
- [Fix] `duplicates` option should not apply to bracket notation keys (#514)
|
package/README.md
CHANGED
|
@@ -183,7 +183,7 @@ var withDots = qs.parse('name%252Eobj.first=John&name%252Eobj.last=Doe', { decod
|
|
|
183
183
|
assert.deepEqual(withDots, { 'name.obj': { first: 'John', last: 'Doe' }});
|
|
184
184
|
```
|
|
185
185
|
|
|
186
|
-
Option `allowEmptyArrays` can be used to
|
|
186
|
+
Option `allowEmptyArrays` can be used to allow empty array values in an object
|
|
187
187
|
```javascript
|
|
188
188
|
var withEmptyArrays = qs.parse('foo[]&bar=baz', { allowEmptyArrays: true });
|
|
189
189
|
assert.deepEqual(withEmptyArrays, { foo: [], bar: 'baz' });
|
package/dist/qs.js
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
"use strict";var stringify=require(4),parse=require(3),formats=require(1);module.exports={formats:formats,parse:parse,stringify:stringify};
|
|
6
6
|
|
|
7
7
|
},{"1":1,"3":3,"4":4}],3:[function(require,module,exports){
|
|
8
|
-
"use strict";var utils=require(5),has=Object.prototype.hasOwnProperty,isArray=Array.isArray,defaults={allowDots:!1,allowEmptyArrays:!1,allowPrototypes:!1,allowSparse:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decodeDotInKeys:!1,decoder:utils.decode,delimiter:"&",depth:5,duplicates:"combine",ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictDepth:!1,strictMerge:!0,strictNullHandling:!1,throwOnLimitExceeded:!1},interpretNumericEntities=function(e){return e.replace(/&#(\d+);/g,function(e,t){return String.fromCharCode(parseInt(t,10))})},parseArrayValue=function(e,t,r){if(e&&"string"==typeof e&&t.comma&&e.indexOf(",")>-1)return e.split(",");if(t.throwOnLimitExceeded&&r>=t.arrayLimit)throw new RangeError("Array limit exceeded. Only "+t.arrayLimit+" element"+(1===t.arrayLimit?"":"s")+" allowed in an array.");return e},isoSentinel="utf8=%26%2310003%3B",charsetSentinel="utf8=%E2%9C%93",parseValues=function parseQueryStringValues(e,t){var r={__proto__:null},i=t.ignoreQueryPrefix?e.replace(/^\?/,""):e;i=i.replace(/%5B/gi,"[").replace(/%5D/gi,"]");var a=t.parameterLimit===1/0?void 0:t.parameterLimit,o=i.split(t.delimiter,t.throwOnLimitExceeded?a+1:a);if(t.throwOnLimitExceeded&&o.length>a)throw new RangeError("Parameter limit exceeded. Only "+a+" parameter"+(1===a?"":"s")+" allowed.");var l,n=-1,s=t.charset;if(t.charsetSentinel)for(l=0;l<o.length;++l)0===o[l].indexOf("utf8=")&&(o[l]===charsetSentinel?s="utf-8":o[l]===isoSentinel&&(s="iso-8859-1"),n=l,l=o.length);for(l=0;l<o.length;++l)if(l!==n){var d,c,p=o[l],u=p.indexOf("]="),y=-1===u?p.indexOf("="):u+1;if(-1===y?(d=t.decoder(p,defaults.decoder,s,"key"),c=t.strictNullHandling?null:""):null!==(d=t.decoder(p.slice(0,y),defaults.decoder,s,"key"))&&(c=utils.maybeMap(parseArrayValue(p.slice(y+1),t,isArray(r[d])?r[d].length:0),function(e){return t.decoder(e,defaults.decoder,s,"value")})),c&&t.interpretNumericEntities&&"iso-8859-1"===s&&(c=interpretNumericEntities(String(c))),p.indexOf("[]=")>-1&&(c=isArray(c)?[c]:c),t.comma&&isArray(c)&&c.length>t.arrayLimit){if(t.throwOnLimitExceeded)throw new RangeError("Array limit exceeded. Only "+t.arrayLimit+" element"+(1===t.arrayLimit?"":"s")+" allowed in an array.");c=utils.combine([],c,t.arrayLimit,t.plainObjects)}if(null!==d){var f=has.call(r,d);f&&("combine"===t.duplicates||p.indexOf("[]=")>-1)?r[d]=utils.combine(r[d],c,t.arrayLimit,t.plainObjects):f&&"last"!==t.duplicates||(r[d]=c)}}return r},parseObject=function(e,t,r,i){var a=0;if(e.length>0&&"[]"===e[e.length-1]){var o=e.slice(0,-1).join("");a=Array.isArray(t)&&t[o]?t[o].length:0}for(var l=i?t:parseArrayValue(t,r,a),n=e.length-1;n>=0;--n){var s,d=e[n];if("[]"===d&&r.parseArrays)s=utils.isOverflow(l)?l:r.allowEmptyArrays&&(""===l||r.strictNullHandling&&null===l)?[]:utils.combine([],l,r.arrayLimit,r.plainObjects);else{s=r.plainObjects?{__proto__:null}:{};var c="["===d.charAt(0)&&"]"===d.charAt(d.length-1)?d.slice(1,-1):d,p=r.decodeDotInKeys?c.replace(/%2E/g,"."):c,u=parseInt(p,10),y=!isNaN(u)&&d!==p&&String(u)===p&&u>=0&&r.parseArrays;if(r.parseArrays||""!==p)if(y&&u<r.arrayLimit)(s=[])[u]=l;else{if(y&&r.throwOnLimitExceeded)throw new RangeError("Array limit exceeded. Only "+r.arrayLimit+" element"+(1===r.arrayLimit?"":"s")+" allowed in an array.");y?(s[u]=l,utils.markOverflow(s,u)):"__proto__"!==p&&(s[p]=l)}else s={0:l}}l=s}return l},splitKeyIntoSegments=function splitKeyIntoSegments(e,t){var r=t.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e;if(t.depth<=0){if(!t.plainObjects&&has.call(Object.prototype,r)&&!t.allowPrototypes)return;return[r]}var i
|
|
8
|
+
"use strict";var utils=require(5),has=Object.prototype.hasOwnProperty,isArray=Array.isArray,defaults={allowDots:!1,allowEmptyArrays:!1,allowPrototypes:!1,allowSparse:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decodeDotInKeys:!1,decoder:utils.decode,delimiter:"&",depth:5,duplicates:"combine",ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictDepth:!1,strictMerge:!0,strictNullHandling:!1,throwOnLimitExceeded:!1},interpretNumericEntities=function(e){return e.replace(/&#(\d+);/g,function(e,t){return String.fromCharCode(parseInt(t,10))})},parseArrayValue=function(e,t,r){if(e&&"string"==typeof e&&t.comma&&e.indexOf(",")>-1)return e.split(",");if(t.throwOnLimitExceeded&&r>=t.arrayLimit)throw new RangeError("Array limit exceeded. Only "+t.arrayLimit+" element"+(1===t.arrayLimit?"":"s")+" allowed in an array.");return e},isoSentinel="utf8=%26%2310003%3B",charsetSentinel="utf8=%E2%9C%93",parseValues=function parseQueryStringValues(e,t){var r={__proto__:null},i=t.ignoreQueryPrefix?e.replace(/^\?/,""):e;i=i.replace(/%5B/gi,"[").replace(/%5D/gi,"]");var a=t.parameterLimit===1/0?void 0:t.parameterLimit,o=i.split(t.delimiter,t.throwOnLimitExceeded&&void 0!==a?a+1:a);if(t.throwOnLimitExceeded&&void 0!==a&&o.length>a)throw new RangeError("Parameter limit exceeded. Only "+a+" parameter"+(1===a?"":"s")+" allowed.");var l,n=-1,s=t.charset;if(t.charsetSentinel)for(l=0;l<o.length;++l)0===o[l].indexOf("utf8=")&&(o[l]===charsetSentinel?s="utf-8":o[l]===isoSentinel&&(s="iso-8859-1"),n=l,l=o.length);for(l=0;l<o.length;++l)if(l!==n){var d,c,p=o[l],u=p.indexOf("]="),y=-1===u?p.indexOf("="):u+1;if(-1===y?(d=t.decoder(p,defaults.decoder,s,"key"),c=t.strictNullHandling?null:""):null!==(d=t.decoder(p.slice(0,y),defaults.decoder,s,"key"))&&(c=utils.maybeMap(parseArrayValue(p.slice(y+1),t,isArray(r[d])?r[d].length:0),function(e){return t.decoder(e,defaults.decoder,s,"value")})),c&&t.interpretNumericEntities&&"iso-8859-1"===s&&(c=interpretNumericEntities(String(c))),p.indexOf("[]=")>-1&&(c=isArray(c)?[c]:c),t.comma&&isArray(c)&&c.length>t.arrayLimit){if(t.throwOnLimitExceeded)throw new RangeError("Array limit exceeded. Only "+t.arrayLimit+" element"+(1===t.arrayLimit?"":"s")+" allowed in an array.");c=utils.combine([],c,t.arrayLimit,t.plainObjects)}if(null!==d){var f=has.call(r,d);f&&("combine"===t.duplicates||p.indexOf("[]=")>-1)?r[d]=utils.combine(r[d],c,t.arrayLimit,t.plainObjects):f&&"last"!==t.duplicates||(r[d]=c)}}return r},parseObject=function(e,t,r,i){var a=0;if(e.length>0&&"[]"===e[e.length-1]){var o=e.slice(0,-1).join("");a=Array.isArray(t)&&t[o]?t[o].length:0}for(var l=i?t:parseArrayValue(t,r,a),n=e.length-1;n>=0;--n){var s,d=e[n];if("[]"===d&&r.parseArrays)s=utils.isOverflow(l)?l:r.allowEmptyArrays&&(""===l||r.strictNullHandling&&null===l)?[]:utils.combine([],l,r.arrayLimit,r.plainObjects);else{s=r.plainObjects?{__proto__:null}:{};var c="["===d.charAt(0)&&"]"===d.charAt(d.length-1)?d.slice(1,-1):d,p=r.decodeDotInKeys?c.replace(/%2E/g,"."):c,u=parseInt(p,10),y=!isNaN(u)&&d!==p&&String(u)===p&&u>=0&&r.parseArrays;if(r.parseArrays||""!==p)if(y&&u<r.arrayLimit)(s=[])[u]=l;else{if(y&&r.throwOnLimitExceeded)throw new RangeError("Array limit exceeded. Only "+r.arrayLimit+" element"+(1===r.arrayLimit?"":"s")+" allowed in an array.");y?(s[u]=l,utils.markOverflow(s,u)):"__proto__"!==p&&(s[p]=l)}else s={0:l}}l=s}return l},splitKeyIntoSegments=function splitKeyIntoSegments(e,t){var r=t.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e;if(t.depth<=0){if(!t.plainObjects&&has.call(Object.prototype,r)&&!t.allowPrototypes)return;return[r]}var i=[],a=r.indexOf("["),o=a>=0?r.slice(0,a):r;if(o){if(!t.plainObjects&&has.call(Object.prototype,o)&&!t.allowPrototypes)return;i[i.length]=o}for(var l=r.length,n=a,s=0;n>=0&&s<t.depth;){for(var d=1,c=n+1,p=-1;c<l&&p<0;){var u=r.charCodeAt(c);91===u?d+=1:93===u&&0==(d-=1)&&(p=c),c+=1}if(p<0)return i[i.length]="["+r.slice(n)+"]",i;var y=r.slice(n,p+1),f=y.slice(1,-1);if(!t.plainObjects&&has.call(Object.prototype,f)&&!t.allowPrototypes)return;i[i.length]=y,s+=1,n=r.indexOf("[",p+1)}if(n>=0){if(!0===t.strictDepth)throw new RangeError("Input depth exceeded depth option of "+t.depth+" and strictDepth is true");i[i.length]="["+r.slice(n)+"]"}return i},parseKeys=function parseQueryStringKeys(e,t,r,i){if(e){var a=splitKeyIntoSegments(e,r);if(a)return parseObject(a,t,r,i)}},normalizeParseOptions=function normalizeParseOptions(e){if(!e)return defaults;if(void 0!==e.allowEmptyArrays&&"boolean"!=typeof e.allowEmptyArrays)throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(void 0!==e.decodeDotInKeys&&"boolean"!=typeof e.decodeDotInKeys)throw new TypeError("`decodeDotInKeys` option can only be `true` or `false`, when provided");if(null!==e.decoder&&void 0!==e.decoder&&"function"!=typeof e.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");if(void 0!==e.throwOnLimitExceeded&&"boolean"!=typeof e.throwOnLimitExceeded)throw new TypeError("`throwOnLimitExceeded` option must be a boolean");var t=void 0===e.charset?defaults.charset:e.charset,r=void 0===e.duplicates?defaults.duplicates:e.duplicates;if("combine"!==r&&"first"!==r&&"last"!==r)throw new TypeError("The duplicates option must be either combine, first, or last");return{allowDots:void 0===e.allowDots?!0===e.decodeDotInKeys||defaults.allowDots:!!e.allowDots,allowEmptyArrays:"boolean"==typeof e.allowEmptyArrays?!!e.allowEmptyArrays:defaults.allowEmptyArrays,allowPrototypes:"boolean"==typeof e.allowPrototypes?e.allowPrototypes:defaults.allowPrototypes,allowSparse:"boolean"==typeof e.allowSparse?e.allowSparse:defaults.allowSparse,arrayLimit:"number"==typeof e.arrayLimit?e.arrayLimit:defaults.arrayLimit,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:defaults.charsetSentinel,comma:"boolean"==typeof e.comma?e.comma:defaults.comma,decodeDotInKeys:"boolean"==typeof e.decodeDotInKeys?e.decodeDotInKeys:defaults.decodeDotInKeys,decoder:"function"==typeof e.decoder?e.decoder:defaults.decoder,delimiter:"string"==typeof e.delimiter||utils.isRegExp(e.delimiter)?e.delimiter:defaults.delimiter,depth:"number"==typeof e.depth||!1===e.depth?+e.depth:defaults.depth,duplicates:r,ignoreQueryPrefix:!0===e.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof e.interpretNumericEntities?e.interpretNumericEntities:defaults.interpretNumericEntities,parameterLimit:"number"==typeof e.parameterLimit?e.parameterLimit:defaults.parameterLimit,parseArrays:!1!==e.parseArrays,plainObjects:"boolean"==typeof e.plainObjects?e.plainObjects:defaults.plainObjects,strictDepth:"boolean"==typeof e.strictDepth?!!e.strictDepth:defaults.strictDepth,strictMerge:"boolean"==typeof e.strictMerge?!!e.strictMerge:defaults.strictMerge,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:defaults.strictNullHandling,throwOnLimitExceeded:"boolean"==typeof e.throwOnLimitExceeded&&e.throwOnLimitExceeded}};module.exports=function(e,t){var r=normalizeParseOptions(t);if(""===e||null==e)return r.plainObjects?{__proto__:null}:{};for(var i="string"==typeof e?parseValues(e,r):e,a=r.plainObjects?{__proto__:null}:{},o=Object.keys(i),l=0;l<o.length;++l){var n=o[l],s=parseKeys(n,i[n],r,"string"==typeof e);a=utils.merge(a,s,r)}return!0===r.allowSparse?a:utils.compact(a)};
|
|
9
9
|
|
|
10
10
|
},{"5":5}],4:[function(require,module,exports){
|
|
11
|
-
"use strict";var getSideChannel=require(46),utils=require(5),formats=require(1),has=Object.prototype.hasOwnProperty,arrayPrefixGenerators={brackets:function brackets(e){return e+"[]"},comma:"comma",indices:function indices(e,r){return e+"["+r+"]"},repeat:function repeat(e){return e}},isArray=Array.isArray,push=Array.prototype.push,pushToArray=function(e,r){push.apply(e,isArray(r)?r:[r])},toISO=Date.prototype.toISOString,defaultFormat=formats.default,defaults={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,commaRoundTrip:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:utils.encode,encodeValuesOnly:!1,filter:void 0,format:defaultFormat,formatter:formats.formatters[defaultFormat],indices:!1,serializeDate:function serializeDate(e){return toISO.call(e)},skipNulls:!1,strictNullHandling:!1},isNonNullishPrimitive=function isNonNullishPrimitive(e){return"string"==typeof e||"number"==typeof e||"boolean"==typeof e||"symbol"==typeof e||"bigint"==typeof e},sentinel={},stringify=function stringify(e,r,t,o,a,n,i,l,s,f,u,d,y,c,p,m,h,v){for(var g=e,w=v,b=0,A=!1;void 0!==(w=w.get(sentinel))&&!A;){var D=w.get(e);if(b+=1,void 0!==D){if(D===b)throw new RangeError("Cyclic object value");A=!0}void 0===w.get(sentinel)&&(b=0)}if("function"==typeof f?g=f(r,g):g instanceof Date?g=y(g):"comma"===t&&isArray(g)&&(g=utils.maybeMap(g,function(e){return e instanceof Date?y(e):e})),null===g){if(n)return s&&!m?s(r,defaults.encoder,h,"key",c):r;g=""}if(isNonNullishPrimitive(g)||utils.isBuffer(g))return s?[p(m?r:s(r,defaults.encoder,h,"key",c))+"="+p(s(g,defaults.encoder,h,"value",c))]:[p(r)+"="+p(String(g))];var S,E=[];if(void 0===g)return E;if("comma"===t&&isArray(g))m&&s&&(g=utils.maybeMap(g,s)),S=[{value:g.length>0?g.join(",")||null:void 0}];else if(isArray(f))S=f;else{var N=Object.keys(g);S=u?N.sort(u):N}var T=l?String(r).replace(/\./g,"%2E"):String(r),O=o&&isArray(g)&&1===g.length?T+"[]":T;if(a&&isArray(g)&&0===g.length)return O+"[]";for(var k=0;k<S.length;++k){var I=S[k],P="object"==typeof I&&I&&void 0!==I.value?I.value:g[I];if(!i||null!==P){var x=d&&l?String(I).replace(/\./g,"%2E"):String(I),z=isArray(g)?"function"==typeof t?t(O,x):O:O+(d?"."+x:"["+x+"]");v.set(e,b);var K=getSideChannel();K.set(sentinel,v),pushToArray(E,stringify(P,z,t,o,a,n,i,l,"comma"===t&&m&&isArray(g)?null:s,f,u,d,y,c,p,m,h,K))}}return E},normalizeStringifyOptions=function normalizeStringifyOptions(e){if(!e)return defaults;if(void 0!==e.allowEmptyArrays&&"boolean"!=typeof e.allowEmptyArrays)throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(void 0!==e.encodeDotInKeys&&"boolean"!=typeof e.encodeDotInKeys)throw new TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");if(null!==e.encoder&&void 0!==e.encoder&&"function"!=typeof e.encoder)throw new TypeError("Encoder has to be a function.");var r=e.charset||defaults.charset;if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var t=formats.default;if(void 0!==e.format){if(!has.call(formats.formatters,e.format))throw new TypeError("Unknown format option provided.");t=e.format}var o,a=formats.formatters[t],n=defaults.filter;if(("function"==typeof e.filter||isArray(e.filter))&&(n=e.filter),o=e.arrayFormat in arrayPrefixGenerators?e.arrayFormat:"indices"in e?e.indices?"indices":"repeat":defaults.arrayFormat,"commaRoundTrip"in e&&"boolean"!=typeof e.commaRoundTrip)throw new TypeError("`commaRoundTrip` must be a boolean, or absent");var i=void 0===e.allowDots?!0===e.encodeDotInKeys||defaults.allowDots:!!e.allowDots;return{addQueryPrefix:"boolean"==typeof e.addQueryPrefix?e.addQueryPrefix:defaults.addQueryPrefix,allowDots:i,allowEmptyArrays:"boolean"==typeof e.allowEmptyArrays?!!e.allowEmptyArrays:defaults.allowEmptyArrays,arrayFormat:o,charset:r,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:defaults.charsetSentinel,commaRoundTrip:!!e.commaRoundTrip,delimiter:void 0===e.delimiter?defaults.delimiter:e.delimiter,encode:"boolean"==typeof e.encode?e.encode:defaults.encode,encodeDotInKeys:"boolean"==typeof e.encodeDotInKeys?e.encodeDotInKeys:defaults.encodeDotInKeys,encoder:"function"==typeof e.encoder?e.encoder:defaults.encoder,encodeValuesOnly:"boolean"==typeof e.encodeValuesOnly?e.encodeValuesOnly:defaults.encodeValuesOnly,filter:n,format:t,formatter:a,serializeDate:"function"==typeof e.serializeDate?e.serializeDate:defaults.serializeDate,skipNulls:"boolean"==typeof e.skipNulls?e.skipNulls:defaults.skipNulls,sort:"function"==typeof e.sort?e.sort:null,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:defaults.strictNullHandling}};module.exports=function(e,r){var t,o=e,a=normalizeStringifyOptions(r);"function"==typeof a.filter?o=(0,a.filter)("",o):isArray(a.filter)&&(t=a.filter);var n=[];if("object"!=typeof o||null===o)return"";var i=arrayPrefixGenerators[a.arrayFormat],l="comma"===i&&a.commaRoundTrip;t||(t=Object.keys(o)),a.sort&&t.sort(a.sort);for(var s=getSideChannel(),f=0;f<t.length;++f){var u=t[f]
|
|
11
|
+
"use strict";var getSideChannel=require(46),utils=require(5),formats=require(1),has=Object.prototype.hasOwnProperty,arrayPrefixGenerators={brackets:function brackets(e){return e+"[]"},comma:"comma",indices:function indices(e,r){return e+"["+r+"]"},repeat:function repeat(e){return e}},isArray=Array.isArray,push=Array.prototype.push,pushToArray=function(e,r){push.apply(e,isArray(r)?r:[r])},toISO=Date.prototype.toISOString,defaultFormat=formats.default,defaults={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,commaRoundTrip:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:utils.encode,encodeValuesOnly:!1,filter:void 0,format:defaultFormat,formatter:formats.formatters[defaultFormat],indices:!1,serializeDate:function serializeDate(e){return toISO.call(e)},skipNulls:!1,strictNullHandling:!1},isNonNullishPrimitive=function isNonNullishPrimitive(e){return"string"==typeof e||"number"==typeof e||"boolean"==typeof e||"symbol"==typeof e||"bigint"==typeof e},sentinel={},stringify=function stringify(e,r,t,o,a,n,i,l,s,f,u,d,y,c,p,m,h,v){for(var g=e,w=v,b=0,A=!1;void 0!==(w=w.get(sentinel))&&!A;){var D=w.get(e);if(b+=1,void 0!==D){if(D===b)throw new RangeError("Cyclic object value");A=!0}void 0===w.get(sentinel)&&(b=0)}if("function"==typeof f?g=f(r,g):g instanceof Date?g=y(g):"comma"===t&&isArray(g)&&(g=utils.maybeMap(g,function(e){return e instanceof Date?y(e):e})),null===g){if(n)return p(s&&!m?s(r,defaults.encoder,h,"key",c):r);g=""}if(isNonNullishPrimitive(g)||utils.isBuffer(g))return s?[p(m?r:s(r,defaults.encoder,h,"key",c))+"="+p(s(g,defaults.encoder,h,"value",c))]:[p(r)+"="+p(String(g))];var S,E=[];if(void 0===g)return E;if("comma"===t&&isArray(g))m&&s&&(g=utils.maybeMap(g,function(e){return null==e?e:s(e)})),S=[{value:g.length>0?g.join(",")||null:void 0}];else if(isArray(f))S=f;else{var N=Object.keys(g);S=u?N.sort(u):N}var T=l?String(r).replace(/\./g,"%2E"):String(r),O=o&&isArray(g)&&1===g.length?T+"[]":T;if(a&&isArray(g)&&0===g.length)return O+"[]";for(var k=0;k<S.length;++k){var I=S[k],P="object"==typeof I&&I&&void 0!==I.value?I.value:g[I];if(!i||null!==P){var x=d&&l?String(I).replace(/\./g,"%2E"):String(I),z=isArray(g)?"function"==typeof t?t(O,x):O:O+(d?"."+x:"["+x+"]");v.set(e,b);var K=getSideChannel();K.set(sentinel,v),pushToArray(E,stringify(P,z,t,o,a,n,i,l,"comma"===t&&m&&isArray(g)?null:s,f,u,d,y,c,p,m,h,K))}}return E},normalizeStringifyOptions=function normalizeStringifyOptions(e){if(!e)return defaults;if(void 0!==e.allowEmptyArrays&&"boolean"!=typeof e.allowEmptyArrays)throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(void 0!==e.encodeDotInKeys&&"boolean"!=typeof e.encodeDotInKeys)throw new TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");if(null!==e.encoder&&void 0!==e.encoder&&"function"!=typeof e.encoder)throw new TypeError("Encoder has to be a function.");var r=e.charset||defaults.charset;if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var t=formats.default;if(void 0!==e.format){if(!has.call(formats.formatters,e.format))throw new TypeError("Unknown format option provided.");t=e.format}var o,a=formats.formatters[t],n=defaults.filter;if(("function"==typeof e.filter||isArray(e.filter))&&(n=e.filter),o=e.arrayFormat in arrayPrefixGenerators?e.arrayFormat:"indices"in e?e.indices?"indices":"repeat":defaults.arrayFormat,"commaRoundTrip"in e&&"boolean"!=typeof e.commaRoundTrip)throw new TypeError("`commaRoundTrip` must be a boolean, or absent");var i=void 0===e.allowDots?!0===e.encodeDotInKeys||defaults.allowDots:!!e.allowDots;return{addQueryPrefix:"boolean"==typeof e.addQueryPrefix?e.addQueryPrefix:defaults.addQueryPrefix,allowDots:i,allowEmptyArrays:"boolean"==typeof e.allowEmptyArrays?!!e.allowEmptyArrays:defaults.allowEmptyArrays,arrayFormat:o,charset:r,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:defaults.charsetSentinel,commaRoundTrip:!!e.commaRoundTrip,delimiter:void 0===e.delimiter?defaults.delimiter:e.delimiter,encode:"boolean"==typeof e.encode?e.encode:defaults.encode,encodeDotInKeys:"boolean"==typeof e.encodeDotInKeys?e.encodeDotInKeys:defaults.encodeDotInKeys,encoder:"function"==typeof e.encoder?e.encoder:defaults.encoder,encodeValuesOnly:"boolean"==typeof e.encodeValuesOnly?e.encodeValuesOnly:defaults.encodeValuesOnly,filter:n,format:t,formatter:a,serializeDate:"function"==typeof e.serializeDate?e.serializeDate:defaults.serializeDate,skipNulls:"boolean"==typeof e.skipNulls?e.skipNulls:defaults.skipNulls,sort:"function"==typeof e.sort?e.sort:null,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:defaults.strictNullHandling}};module.exports=function(e,r){var t,o=e,a=normalizeStringifyOptions(r);"function"==typeof a.filter?o=(0,a.filter)("",o):isArray(a.filter)&&(t=a.filter);var n=[];if("object"!=typeof o||null===o)return"";var i=arrayPrefixGenerators[a.arrayFormat],l="comma"===i&&a.commaRoundTrip;t||(t=Object.keys(o)),a.sort&&t.sort(a.sort);for(var s=getSideChannel(),f=0;f<t.length;++f){var u=t[f];if(null!=u){var d=o[u];a.skipNulls&&null===d||pushToArray(n,stringify(d,u,i,l,a.allowEmptyArrays,a.strictNullHandling,a.skipNulls,a.encodeDotInKeys,a.encode?a.encoder:null,a.filter,a.sort,a.allowDots,a.serializeDate,a.format,a.formatter,a.encodeValuesOnly,a.charset,s))}}var y=n.join(a.delimiter),c=!0===a.addQueryPrefix?"?":"";return a.charsetSentinel&&("iso-8859-1"===a.charset?c+="utf8=%26%2310003%3B"+a.delimiter:c+="utf8=%E2%9C%93"+a.delimiter),y.length>0?c+y:""};
|
|
12
12
|
|
|
13
13
|
},{"1":1,"46":46,"5":5}],5:[function(require,module,exports){
|
|
14
14
|
"use strict";var formats=require(1),getSideChannel=require(46),has=Object.prototype.hasOwnProperty,isArray=Array.isArray,overflowChannel=getSideChannel(),markOverflow=function markOverflow(e,r){return overflowChannel.set(e,r),e},isOverflow=function isOverflow(e){return overflowChannel.has(e)},getMaxIndex=function getMaxIndex(e){return overflowChannel.get(e)},setMaxIndex=function setMaxIndex(e,r){overflowChannel.set(e,r)},hexTable=function(){for(var e=[],r=0;r<256;++r)e[e.length]="%"+((r<16?"0":"")+r.toString(16)).toUpperCase();return e}(),compactQueue=function compactQueue(e){for(;e.length>1;){var r=e.pop(),t=r.obj[r.prop];if(isArray(t)){for(var n=[],o=0;o<t.length;++o)void 0!==t[o]&&(n[n.length]=t[o]);r.obj[r.prop]=n}}},arrayToObject=function arrayToObject(e,r){for(var t=r&&r.plainObjects?{__proto__:null}:{},n=0;n<e.length;++n)void 0!==e[n]&&(t[n]=e[n]);return t},merge=function merge(e,r,t){if(!r)return e;if("object"!=typeof r&&"function"!=typeof r){if(isArray(e)){var n=e.length;if(t&&"number"==typeof t.arrayLimit&&n>t.arrayLimit)return markOverflow(arrayToObject(e.concat(r),t),n);e[n]=r}else{if(!e||"object"!=typeof e)return[e,r];if(isOverflow(e)){var o=getMaxIndex(e)+1;e[o]=r,setMaxIndex(e,o)}else{if(t&&t.strictMerge)return[e,r];(t&&(t.plainObjects||t.allowPrototypes)||!has.call(Object.prototype,r))&&(e[r]=!0)}}return e}if(!e||"object"!=typeof e){if(isOverflow(r)){for(var a=Object.keys(r),i=t&&t.plainObjects?{__proto__:null,0:e}:{0:e},c=0;c<a.length;c++)i[parseInt(a[c],10)+1]=r[a[c]];return markOverflow(i,getMaxIndex(r)+1)}var l=[e].concat(r);return t&&"number"==typeof t.arrayLimit&&l.length>t.arrayLimit?markOverflow(arrayToObject(l,t),l.length-1):l}var f=e;return isArray(e)&&!isArray(r)&&(f=arrayToObject(e,t)),isArray(e)&&isArray(r)?(r.forEach(function(r,n){if(has.call(e,n)){var o=e[n];o&&"object"==typeof o&&r&&"object"==typeof r?e[n]=merge(o,r,t):e[e.length]=r}else e[n]=r}),e):Object.keys(r).reduce(function(e,n){var o=r[n];if(has.call(e,n)?e[n]=merge(e[n],o,t):e[n]=o,isOverflow(r)&&!isOverflow(e)&&markOverflow(e,getMaxIndex(r)),isOverflow(e)){var a=parseInt(n,10);String(a)===n&&a>=0&&a>getMaxIndex(e)&&setMaxIndex(e,a)}return e},f)},assign=function assignSingleSource(e,r){return Object.keys(r).reduce(function(e,t){return e[t]=r[t],e},e)},decode=function(e,r,t){var n=e.replace(/\+/g," ");if("iso-8859-1"===t)return n.replace(/%[0-9a-f]{2}/gi,unescape);try{return decodeURIComponent(n)}catch(e){return n}},limit=1024,encode=function encode(e,r,t,n,o){if(0===e.length)return e;var a=e;if("symbol"==typeof e?a=Symbol.prototype.toString.call(e):"string"!=typeof e&&(a=String(e)),"iso-8859-1"===t)return escape(a).replace(/%u[0-9a-f]{4}/gi,function(e){return"%26%23"+parseInt(e.slice(2),16)+"%3B"});for(var i="",c=0;c<a.length;c+=limit){for(var l=a.length>=limit?a.slice(c,c+limit):a,f=[],s=0;s<l.length;++s){var u=l.charCodeAt(s);45===u||46===u||95===u||126===u||u>=48&&u<=57||u>=65&&u<=90||u>=97&&u<=122||o===formats.RFC1738&&(40===u||41===u)?f[f.length]=l.charAt(s):u<128?f[f.length]=hexTable[u]:u<2048?f[f.length]=hexTable[192|u>>6]+hexTable[128|63&u]:u<55296||u>=57344?f[f.length]=hexTable[224|u>>12]+hexTable[128|u>>6&63]+hexTable[128|63&u]:(s+=1,u=65536+((1023&u)<<10|1023&l.charCodeAt(s)),f[f.length]=hexTable[240|u>>18]+hexTable[128|u>>12&63]+hexTable[128|u>>6&63]+hexTable[128|63&u])}i+=f.join("")}return i},compact=function compact(e){for(var r=[{obj:{o:e},prop:"o"}],t=[],n=0;n<r.length;++n)for(var o=r[n],a=o.obj[o.prop],i=Object.keys(a),c=0;c<i.length;++c){var l=i[c],f=a[l];"object"==typeof f&&null!==f&&-1===t.indexOf(f)&&(r[r.length]={obj:a,prop:l},t[t.length]=f)}return compactQueue(r),e},isRegExp=function isRegExp(e){return"[object RegExp]"===Object.prototype.toString.call(e)},isBuffer=function isBuffer(e){return!(!e||"object"!=typeof e||!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e)))},combine=function combine(e,r,t,n){if(isOverflow(e)){var o=getMaxIndex(e)+1;return e[o]=r,setMaxIndex(e,o),e}var a=[].concat(e,r);return a.length>t?markOverflow(arrayToObject(a,{plainObjects:n}),a.length-1):a},maybeMap=function maybeMap(e,r){if(isArray(e)){for(var t=[],n=0;n<e.length;n+=1)t[t.length]=r(e[n]);return t}return r(e)};module.exports={/* common-shake removed: arrayToObject:arrayToObject *//* common-shake removed: assign:assign */combine:combine,compact:compact,decode:decode,encode:encode,isBuffer:isBuffer,isOverflow:isOverflow,isRegExp:isRegExp,markOverflow:markOverflow,maybeMap:maybeMap,merge:merge};
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
},{}],7:[function(require,module,exports){
|
|
22
22
|
"use strict";var bind=require(24),$apply=require(8),$call=require(9),$reflectApply=require(11);module.exports=$reflectApply||bind.call($call,$apply);
|
|
23
23
|
|
|
24
|
-
},{"11":11,"24":24,"8":8,"9":9}],
|
|
25
|
-
"use strict";module.exports=Function.prototype.apply;
|
|
26
|
-
|
|
27
|
-
},{}],9:[function(require,module,exports){
|
|
24
|
+
},{"11":11,"24":24,"8":8,"9":9}],9:[function(require,module,exports){
|
|
28
25
|
"use strict";module.exports=Function.prototype.call;
|
|
29
26
|
|
|
27
|
+
},{}],8:[function(require,module,exports){
|
|
28
|
+
"use strict";module.exports=Function.prototype.apply;
|
|
29
|
+
|
|
30
30
|
},{}],24:[function(require,module,exports){
|
|
31
31
|
"use strict";var implementation=require(23);module.exports=Function.prototype.bind||implementation;
|
|
32
32
|
|
|
@@ -84,9 +84,6 @@
|
|
|
84
84
|
},{}],34:[function(require,module,exports){
|
|
85
85
|
"use strict";module.exports=Math.abs;
|
|
86
86
|
|
|
87
|
-
},{}],39:[function(require,module,exports){
|
|
88
|
-
"use strict";module.exports=Math.pow;
|
|
89
|
-
|
|
90
87
|
},{}],38:[function(require,module,exports){
|
|
91
88
|
"use strict";module.exports=Math.min;
|
|
92
89
|
|
|
@@ -96,22 +93,25 @@
|
|
|
96
93
|
},{}],37:[function(require,module,exports){
|
|
97
94
|
"use strict";module.exports=Math.max;
|
|
98
95
|
|
|
96
|
+
},{}],39:[function(require,module,exports){
|
|
97
|
+
"use strict";module.exports=Math.pow;
|
|
98
|
+
|
|
99
99
|
},{}],27:[function(require,module,exports){
|
|
100
100
|
"use strict";module.exports="undefined"!=typeof Reflect&&Reflect.getPrototypeOf||null;
|
|
101
101
|
|
|
102
102
|
},{}],26:[function(require,module,exports){
|
|
103
103
|
"use strict";var $Object=require(22);module.exports=$Object.getPrototypeOf||null;
|
|
104
104
|
|
|
105
|
-
},{"22":22}],
|
|
105
|
+
},{"22":22}],33:[function(require,module,exports){
|
|
106
|
+
"use strict";var call=Function.prototype.call,$hasOwn=Object.prototype.hasOwnProperty,bind=require(24);module.exports=bind.call(call,$hasOwn);
|
|
107
|
+
|
|
108
|
+
},{"24":24}],41:[function(require,module,exports){
|
|
106
109
|
"use strict";var $isNaN=require(36);module.exports=function sign(i){return $isNaN(i)||0===i?i:i<0?-1:1};
|
|
107
110
|
|
|
108
111
|
},{"36":36}],31:[function(require,module,exports){
|
|
109
112
|
"use strict";var origSymbol="undefined"!=typeof Symbol&&Symbol,hasSymbolSham=require(32);module.exports=function hasNativeSymbols(){return"function"==typeof origSymbol&&"function"==typeof Symbol&&"symbol"==typeof origSymbol("foo")&&"symbol"==typeof Symbol("bar")&&hasSymbolSham()};
|
|
110
113
|
|
|
111
|
-
},{"32":32}],
|
|
112
|
-
"use strict";var call=Function.prototype.call,$hasOwn=Object.prototype.hasOwnProperty,bind=require(24);module.exports=bind.call(call,$hasOwn);
|
|
113
|
-
|
|
114
|
-
},{"24":24}],28:[function(require,module,exports){
|
|
114
|
+
},{"32":32}],28:[function(require,module,exports){
|
|
115
115
|
"use strict";var reflectGetProto=require(27),originalGetProto=require(26),getDunderProto=require(13);module.exports=reflectGetProto?function getProto(t){return reflectGetProto(t)}:originalGetProto?function getProto(t){if(!t||"object"!=typeof t&&"function"!=typeof t)throw new TypeError("getProto: not an object");return originalGetProto(t)}:getDunderProto?function getProto(t){return getDunderProto(t)}:null;
|
|
116
116
|
|
|
117
117
|
},{"13":13,"26":26,"27":27}],29:[function(require,module,exports){
|
|
@@ -129,7 +129,7 @@ var hasMap="function"==typeof Map&&Map.prototype,mapSizeDescriptor=Object.getOwn
|
|
|
129
129
|
|
|
130
130
|
}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
|
131
131
|
},{"6":6}],43:[function(require,module,exports){
|
|
132
|
-
"use strict";var inspect=require(42),$TypeError=require(20),listGetNode=function(e,t,n){for(var i,r=e;null!=(i=r.next);r=i)if(i.key===t)return r.next=i.next,n||(i.next=e.next,e.next=i),i},listGet=function(e,t){if(e){var n=listGetNode(e,t);return n&&n.value}},listSet=function(e,t,n){var i=listGetNode(e,t);i?i.value=n:e.next={key:t,next:e.next,value:n}},listHas=function(e,t){return!!e&&!!listGetNode(e,t)},listDelete=function(e,t){if(e)return listGetNode(e,t,!0)};module.exports=function getSideChannelList(){var e,t={assert:function(e){if(!t.has(e))throw new $TypeError("Side channel does not contain "+inspect(e))},delete:function(t){var n=
|
|
132
|
+
"use strict";var inspect=require(42),$TypeError=require(20),listGetNode=function(e,t,n){for(var i,r=e;null!=(i=r.next);r=i)if(i.key===t)return r.next=i.next,n||(i.next=e.next,e.next=i),i},listGet=function(e,t){if(e){var n=listGetNode(e,t);return n&&n.value}},listSet=function(e,t,n){var i=listGetNode(e,t);i?i.value=n:e.next={key:t,next:e.next,value:n}},listHas=function(e,t){return!!e&&!!listGetNode(e,t)},listDelete=function(e,t){if(e)return listGetNode(e,t,!0)};module.exports=function getSideChannelList(){var e,t={assert:function(e){if(!t.has(e))throw new $TypeError("Side channel does not contain "+inspect(e))},delete:function(t){var n=listDelete(e,t);return n&&e&&!e.next&&(e=void 0),!!n},get:function(t){return listGet(e,t)},has:function(t){return listHas(e,t)},set:function(t,n){e||(e={next:void 0}),listSet(e,t,n)}};return t};
|
|
133
133
|
|
|
134
134
|
},{"20":20,"42":42}],44:[function(require,module,exports){
|
|
135
135
|
"use strict";var GetIntrinsic=require(25),callBound=require(12),inspect=require(42),$TypeError=require(20),$Map=GetIntrinsic("%Map%",!0),$mapGet=callBound("Map.prototype.get",!0),$mapSet=callBound("Map.prototype.set",!0),$mapHas=callBound("Map.prototype.has",!0),$mapDelete=callBound("Map.prototype.delete",!0),$mapSize=callBound("Map.prototype.size",!0);module.exports=!!$Map&&function getSideChannelMap(){var e,t={assert:function(e){if(!t.has(e))throw new $TypeError("Side channel does not contain "+inspect(e))},delete:function(t){if(e){var n=$mapDelete(e,t);return 0===$mapSize(e)&&(e=void 0),n}return!1},get:function(t){if(e)return $mapGet(e,t)},has:function(t){return!!e&&$mapHas(e,t)},set:function(t,n){e||(e=new $Map),$mapSet(e,t,n)}};return t};
|
package/eslint.config.mjs
CHANGED
package/lib/parse.js
CHANGED
|
@@ -67,10 +67,10 @@ var parseValues = function parseQueryStringValues(str, options) {
|
|
|
67
67
|
var limit = options.parameterLimit === Infinity ? void undefined : options.parameterLimit;
|
|
68
68
|
var parts = cleanStr.split(
|
|
69
69
|
options.delimiter,
|
|
70
|
-
options.throwOnLimitExceeded ? limit + 1 : limit
|
|
70
|
+
options.throwOnLimitExceeded && typeof limit !== 'undefined' ? limit + 1 : limit
|
|
71
71
|
);
|
|
72
72
|
|
|
73
|
-
if (options.throwOnLimitExceeded && parts.length > limit) {
|
|
73
|
+
if (options.throwOnLimitExceeded && typeof limit !== 'undefined' && parts.length > limit) {
|
|
74
74
|
throw new RangeError('Parameter limit exceeded. Only ' + limit + ' parameter' + (limit === 1 ? '' : 's') + ' allowed.');
|
|
75
75
|
}
|
|
76
76
|
|
|
@@ -214,9 +214,12 @@ var parseObject = function (chain, val, options, valuesParsed) {
|
|
|
214
214
|
return leaf;
|
|
215
215
|
};
|
|
216
216
|
|
|
217
|
-
|
|
218
|
-
|
|
217
|
+
// Split a key like "a[b][c[]]" into ['a', '[b]', '[c[]]'] while preserving
|
|
218
|
+
// qs parse semantics for depth/prototype guards.
|
|
219
|
+
var splitKeyIntoSegments = function splitKeyIntoSegments(originalKey, options) {
|
|
220
|
+
var key = options.allowDots ? originalKey.replace(/\.([^.[]+)/g, '[$1]') : originalKey;
|
|
219
221
|
|
|
222
|
+
// depth <= 0 keeps the whole key as one segment
|
|
220
223
|
if (options.depth <= 0) {
|
|
221
224
|
if (!options.plainObjects && has.call(Object.prototype, key)) {
|
|
222
225
|
if (!options.allowPrototypes) {
|
|
@@ -227,14 +230,11 @@ var splitKeyIntoSegments = function splitKeyIntoSegments(givenKey, options) {
|
|
|
227
230
|
return [key];
|
|
228
231
|
}
|
|
229
232
|
|
|
230
|
-
var
|
|
231
|
-
var child = /(\[[^[\]]*])/g;
|
|
232
|
-
|
|
233
|
-
var segment = brackets.exec(key);
|
|
234
|
-
var parent = segment ? key.slice(0, segment.index) : key;
|
|
235
|
-
|
|
236
|
-
var keys = [];
|
|
233
|
+
var segments = [];
|
|
237
234
|
|
|
235
|
+
// parent before the first '[' (may be empty if key starts with '[')
|
|
236
|
+
var first = key.indexOf('[');
|
|
237
|
+
var parent = first >= 0 ? key.slice(0, first) : key;
|
|
238
238
|
if (parent) {
|
|
239
239
|
if (!options.plainObjects && has.call(Object.prototype, parent)) {
|
|
240
240
|
if (!options.allowPrototypes) {
|
|
@@ -242,32 +242,62 @@ var splitKeyIntoSegments = function splitKeyIntoSegments(givenKey, options) {
|
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
-
|
|
245
|
+
segments[segments.length] = parent;
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
-
var
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
248
|
+
var n = key.length;
|
|
249
|
+
var open = first;
|
|
250
|
+
var collected = 0;
|
|
251
|
+
|
|
252
|
+
while (open >= 0 && collected < options.depth) {
|
|
253
|
+
var level = 1;
|
|
254
|
+
var i = open + 1;
|
|
255
|
+
var close = -1;
|
|
256
|
+
|
|
257
|
+
// balance nested '[' and ']' inside this bracket group using a nesting level counter
|
|
258
|
+
while (i < n && close < 0) {
|
|
259
|
+
var cu = key.charCodeAt(i);
|
|
260
|
+
if (cu === 0x5B) { // '['
|
|
261
|
+
level += 1;
|
|
262
|
+
} else if (cu === 0x5D) { // ']'
|
|
263
|
+
level -= 1;
|
|
264
|
+
if (level === 0) {
|
|
265
|
+
close = i; // found matching close; loop will exit by condition
|
|
266
|
+
}
|
|
256
267
|
}
|
|
268
|
+
i += 1;
|
|
257
269
|
}
|
|
258
270
|
|
|
259
|
-
|
|
271
|
+
if (close < 0) {
|
|
272
|
+
// Unterminated group: wrap the raw remainder in one bracket pair so it stays
|
|
273
|
+
// a single literal segment (e.g. "[[]b" -> "[[]b]"); we do not infer missing ']'.
|
|
274
|
+
segments[segments.length] = '[' + key.slice(open) + ']';
|
|
275
|
+
return segments;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
var seg = key.slice(open, close + 1);
|
|
279
|
+
// prototype guard for the content of this group
|
|
280
|
+
var content = seg.slice(1, -1);
|
|
281
|
+
if (!options.plainObjects && has.call(Object.prototype, content) && !options.allowPrototypes) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
segments[segments.length] = seg;
|
|
286
|
+
collected += 1;
|
|
287
|
+
|
|
288
|
+
// find the next '[' after this balanced group
|
|
289
|
+
open = key.indexOf('[', close + 1);
|
|
260
290
|
}
|
|
261
291
|
|
|
262
|
-
if (
|
|
292
|
+
if (open >= 0) {
|
|
263
293
|
if (options.strictDepth === true) {
|
|
264
294
|
throw new RangeError('Input depth exceeded depth option of ' + options.depth + ' and strictDepth is true');
|
|
265
295
|
}
|
|
266
296
|
|
|
267
|
-
|
|
297
|
+
segments[segments.length] = '[' + key.slice(open) + ']';
|
|
268
298
|
}
|
|
269
299
|
|
|
270
|
-
return
|
|
300
|
+
return segments;
|
|
271
301
|
};
|
|
272
302
|
|
|
273
303
|
var parseKeys = function parseQueryStringKeys(givenKey, val, options, valuesParsed) {
|
package/lib/stringify.js
CHANGED
|
@@ -118,7 +118,7 @@ var stringify = function stringify(
|
|
|
118
118
|
|
|
119
119
|
if (obj === null) {
|
|
120
120
|
if (strictNullHandling) {
|
|
121
|
-
return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder, charset, 'key', format) : prefix;
|
|
121
|
+
return formatter(encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder, charset, 'key', format) : prefix);
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
obj = '';
|
|
@@ -142,7 +142,9 @@ var stringify = function stringify(
|
|
|
142
142
|
if (generateArrayPrefix === 'comma' && isArray(obj)) {
|
|
143
143
|
// we need to join elements in
|
|
144
144
|
if (encodeValuesOnly && encoder) {
|
|
145
|
-
obj = utils.maybeMap(obj,
|
|
145
|
+
obj = utils.maybeMap(obj, function (v) {
|
|
146
|
+
return v == null ? v : encoder(v);
|
|
147
|
+
});
|
|
146
148
|
}
|
|
147
149
|
objKeys = [{ value: obj.length > 0 ? obj.join(',') || null : void undefined }];
|
|
148
150
|
} else if (isArray(filter)) {
|
|
@@ -312,6 +314,11 @@ module.exports = function (object, opts) {
|
|
|
312
314
|
var sideChannel = getSideChannel();
|
|
313
315
|
for (var i = 0; i < objKeys.length; ++i) {
|
|
314
316
|
var key = objKeys[i];
|
|
317
|
+
|
|
318
|
+
if (typeof key === 'undefined' || key === null) {
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
|
|
315
322
|
var value = obj[key];
|
|
316
323
|
|
|
317
324
|
if (options.skipNulls && value === null) {
|
|
@@ -345,10 +352,10 @@ module.exports = function (object, opts) {
|
|
|
345
352
|
if (options.charsetSentinel) {
|
|
346
353
|
if (options.charset === 'iso-8859-1') {
|
|
347
354
|
// encodeURIComponent('✓'), the "numeric entity" representation of a checkmark
|
|
348
|
-
prefix += 'utf8=%26%2310003%3B
|
|
355
|
+
prefix += 'utf8=%26%2310003%3B' + options.delimiter;
|
|
349
356
|
} else {
|
|
350
357
|
// encodeURIComponent('✓')
|
|
351
|
-
prefix += 'utf8=%E2%9C%93
|
|
358
|
+
prefix += 'utf8=%E2%9C%93' + options.delimiter;
|
|
352
359
|
}
|
|
353
360
|
}
|
|
354
361
|
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "qs",
|
|
3
3
|
"description": "A querystring parser that supports nesting and arrays, with a depth limit",
|
|
4
4
|
"homepage": "https://github.com/ljharb/qs",
|
|
5
|
-
"version": "6.15.
|
|
5
|
+
"version": "6.15.2",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/ljharb/qs.git"
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@browserify/envify": "^6.0.0",
|
|
38
38
|
"@browserify/uglifyify": "^6.0.0",
|
|
39
|
-
"@ljharb/eslint-config": "^22.
|
|
39
|
+
"@ljharb/eslint-config": "^22.2.3",
|
|
40
40
|
"browserify": "^16.5.2",
|
|
41
41
|
"bundle-collapser": "^1.4.0",
|
|
42
42
|
"common-shakeify": "~1.0.0",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"has-property-descriptors": "^1.0.2",
|
|
52
52
|
"has-proto": "^1.2.0",
|
|
53
53
|
"has-symbols": "^1.1.0",
|
|
54
|
-
"iconv-lite": "^0.5.
|
|
54
|
+
"iconv-lite": "^0.5.2",
|
|
55
55
|
"in-publish": "^2.0.1",
|
|
56
56
|
"jackspeak": "=2.1.1",
|
|
57
57
|
"jiti": "^0.0.0",
|
package/test/parse.js
CHANGED
|
@@ -210,6 +210,21 @@ test('parse()', function (t) {
|
|
|
210
210
|
t.test('uses original key when depth = 0', function (st) {
|
|
211
211
|
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { depth: 0 }), { 'a[0]': 'b', 'a[1]': 'c' });
|
|
212
212
|
st.deepEqual(qs.parse('a[0][0]=b&a[0][1]=c&a[1]=d&e=2', { depth: 0 }), { 'a[0][0]': 'b', 'a[0][1]': 'c', 'a[1]': 'd', e: '2' });
|
|
213
|
+
st.deepEqual(qs.parse('a.b=c', { depth: 0, allowDots: true }), { 'a[b]': 'c' }, 'normalizes dots before applying depth-0 behavior');
|
|
214
|
+
st.deepEqual(qs.parse('toString=foo', { depth: 0 }), {}, 'respects prototype guard at depth 0');
|
|
215
|
+
st.deepEqual(qs.parse('toString=foo', { depth: 0, allowPrototypes: true }), { toString: 'foo' }, 'allows prototypes at depth 0 when enabled');
|
|
216
|
+
st.end();
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
t.test('ignores prototype keys when depth = 0 and allowPrototypes is false', function (st) {
|
|
220
|
+
st.deepEqual(qs.parse('toString=foo', { depth: 0 }), {});
|
|
221
|
+
st.deepEqual(qs.parse('hasOwnProperty=bar', { depth: 0 }), {});
|
|
222
|
+
st.deepEqual(qs.parse('toString=foo&a=b', { depth: 0 }), { a: 'b' });
|
|
223
|
+
st.end();
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
t.test('allows prototype keys when depth = 0 and allowPrototypes is true', function (st) {
|
|
227
|
+
st.deepEqual(qs.parse('toString=foo', { depth: 0, allowPrototypes: true }), { toString: 'foo' });
|
|
213
228
|
st.end();
|
|
214
229
|
});
|
|
215
230
|
|
|
@@ -251,6 +266,52 @@ test('parse()', function (t) {
|
|
|
251
266
|
st.end();
|
|
252
267
|
});
|
|
253
268
|
|
|
269
|
+
t.test('parses keys with literal [] inside a bracket group (#493)', function (st) {
|
|
270
|
+
// A bracket pair inside a bracket group should be treated literally as part of the key
|
|
271
|
+
st.deepEqual(
|
|
272
|
+
qs.parse('search[withbracket[]]=foobar'),
|
|
273
|
+
{ search: { 'withbracket[]': 'foobar' } },
|
|
274
|
+
'treats inner [] literally when inside a bracket group'
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
// Single-level variant
|
|
278
|
+
st.deepEqual(
|
|
279
|
+
qs.parse('a[b[]]=c'),
|
|
280
|
+
{ a: { 'b[]': 'c' } },
|
|
281
|
+
'keeps "b[]" as a literal key'
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
// Nested with an array push on the outer level
|
|
285
|
+
st.deepEqual(
|
|
286
|
+
qs.parse('list[][x[]]=y'),
|
|
287
|
+
{ list: [{ 'x[]': 'y' }] },
|
|
288
|
+
'preserves inner [] while still treating outer [] as array push'
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
// Multiple nested bracket pairs: inner [] remains literal as part of the key
|
|
292
|
+
st.deepEqual(
|
|
293
|
+
qs.parse('a[b[c[]]]=d'),
|
|
294
|
+
{ a: { 'b[c[]]': 'd' } },
|
|
295
|
+
'treats "b[c[]]" as a literal key inside the bracket group'
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
// Depth limits with literal brackets: preserve inner [] while limiting bracket-group parsing
|
|
299
|
+
st.deepEqual(
|
|
300
|
+
qs.parse('a[b[c[]]][d]=e', { depth: 1 }),
|
|
301
|
+
{ a: { 'b[c[]]': { '[d]': 'e' } } },
|
|
302
|
+
'respects depth: 1 and preserves literal inner [] in the parsed key'
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
// Unterminated inner bracket group is wrapped as a literal remainder segment
|
|
306
|
+
st.deepEqual(
|
|
307
|
+
qs.parse('a[[]b=c'),
|
|
308
|
+
{ a: { '[[]b': 'c' } },
|
|
309
|
+
'handles unterminated inner bracket groups without throwing'
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
st.end();
|
|
313
|
+
});
|
|
314
|
+
|
|
254
315
|
t.test('allows to specify array indices', function (st) {
|
|
255
316
|
st.deepEqual(qs.parse('a[1]=c&a[0]=b&a[2]=d'), { a: ['b', 'c', 'd'] });
|
|
256
317
|
st.deepEqual(qs.parse('a[1]=c&a[0]=b'), { a: ['b', 'c'] });
|
|
@@ -1074,6 +1135,15 @@ test('parse()', function (t) {
|
|
|
1074
1135
|
};
|
|
1075
1136
|
|
|
1076
1137
|
st.deepEqual(qs.parse('KeY=vAlUe', { decoder: decoder }), { key: 'VALUE' });
|
|
1138
|
+
|
|
1139
|
+
var noopDecoder = function () { return 'x'; };
|
|
1140
|
+
noopDecoder();
|
|
1141
|
+
st['throws'](
|
|
1142
|
+
function () { decoder('x', noopDecoder, 'utf-8', 'unknown'); },
|
|
1143
|
+
'this should never happen! type: unknown',
|
|
1144
|
+
'decoder throws for unexpected type'
|
|
1145
|
+
);
|
|
1146
|
+
|
|
1077
1147
|
st.end();
|
|
1078
1148
|
});
|
|
1079
1149
|
|
|
@@ -1103,6 +1173,14 @@ test('parse()', function (t) {
|
|
|
1103
1173
|
new RangeError('Parameter limit exceeded. Only 3 parameters allowed.'),
|
|
1104
1174
|
'throws error when parameter limit is exceeded'
|
|
1105
1175
|
);
|
|
1176
|
+
|
|
1177
|
+
sst['throws'](
|
|
1178
|
+
function () {
|
|
1179
|
+
qs.parse('a=1&b=2', { parameterLimit: 1, throwOnLimitExceeded: true });
|
|
1180
|
+
},
|
|
1181
|
+
new RangeError('Parameter limit exceeded. Only 1 parameter allowed.'),
|
|
1182
|
+
'throws error with singular "parameter" when parameterLimit is 1'
|
|
1183
|
+
);
|
|
1106
1184
|
sst.end();
|
|
1107
1185
|
});
|
|
1108
1186
|
|
|
@@ -1124,6 +1202,12 @@ test('parse()', function (t) {
|
|
|
1124
1202
|
sst.end();
|
|
1125
1203
|
});
|
|
1126
1204
|
|
|
1205
|
+
st.test('allows unlimited parameters when parameterLimit is Infinity and throwOnLimitExceeded is true', function (sst) {
|
|
1206
|
+
var result = qs.parse('a=1&b=2&c=3&d=4&e=5&f=6', { parameterLimit: Infinity, throwOnLimitExceeded: true });
|
|
1207
|
+
sst.deepEqual(result, { a: '1', b: '2', c: '3', d: '4', e: '5', f: '6' }, 'parses all parameters without truncation or throwing');
|
|
1208
|
+
sst.end();
|
|
1209
|
+
});
|
|
1210
|
+
|
|
1127
1211
|
st.end();
|
|
1128
1212
|
});
|
|
1129
1213
|
|
|
@@ -1189,6 +1273,14 @@ test('parse()', function (t) {
|
|
|
1189
1273
|
'throws error when a sparse index exceeds arrayLimit'
|
|
1190
1274
|
);
|
|
1191
1275
|
|
|
1276
|
+
sst['throws'](
|
|
1277
|
+
function () {
|
|
1278
|
+
qs.parse('a[2]=b', { arrayLimit: 1, throwOnLimitExceeded: true });
|
|
1279
|
+
},
|
|
1280
|
+
new RangeError('Array limit exceeded. Only 1 element allowed in an array.'),
|
|
1281
|
+
'throws error with singular "element" when arrayLimit is 1'
|
|
1282
|
+
);
|
|
1283
|
+
|
|
1192
1284
|
sst.end();
|
|
1193
1285
|
});
|
|
1194
1286
|
|
|
@@ -1206,6 +1298,17 @@ test('parse()', function (t) {
|
|
|
1206
1298
|
sst.end();
|
|
1207
1299
|
});
|
|
1208
1300
|
|
|
1301
|
+
st.test('throws when duplicate bracket keys exceed arrayLimit with throwOnLimitExceeded', function (sst) {
|
|
1302
|
+
sst['throws'](
|
|
1303
|
+
function () {
|
|
1304
|
+
qs.parse('a[]=1&a[]=2&a[]=3&a[]=4&a[]=5&a[]=6', { arrayLimit: 5, throwOnLimitExceeded: true });
|
|
1305
|
+
},
|
|
1306
|
+
new RangeError('Array limit exceeded. Only 5 elements allowed in an array.'),
|
|
1307
|
+
'throws error when duplicate bracket notation exceeds array limit'
|
|
1308
|
+
);
|
|
1309
|
+
sst.end();
|
|
1310
|
+
});
|
|
1311
|
+
|
|
1209
1312
|
st.end();
|
|
1210
1313
|
});
|
|
1211
1314
|
|
|
@@ -1462,6 +1565,14 @@ test('comma + arrayLimit', function (t) {
|
|
|
1462
1565
|
new RangeError('Array limit exceeded. Only 3 elements allowed in an array.'),
|
|
1463
1566
|
'throws error when comma-split exceeds array limit'
|
|
1464
1567
|
);
|
|
1568
|
+
|
|
1569
|
+
st['throws'](
|
|
1570
|
+
function () {
|
|
1571
|
+
qs.parse('a=1,2,3', { comma: true, arrayLimit: 1, throwOnLimitExceeded: true });
|
|
1572
|
+
},
|
|
1573
|
+
new RangeError('Array limit exceeded. Only 1 element allowed in an array.'),
|
|
1574
|
+
'throws error with singular "element" when arrayLimit is 1'
|
|
1575
|
+
);
|
|
1465
1576
|
st.end();
|
|
1466
1577
|
});
|
|
1467
1578
|
|
|
@@ -1564,5 +1675,29 @@ test('mixed array and object notation', function (t) {
|
|
|
1564
1675
|
st.end();
|
|
1565
1676
|
});
|
|
1566
1677
|
|
|
1678
|
+
t.test('uses existing array length for currentArrayLength when parsing object input with bracket keys', function (st) {
|
|
1679
|
+
var input = {};
|
|
1680
|
+
var arr = ['x', 'y'];
|
|
1681
|
+
arr.a = ['z', 'w'];
|
|
1682
|
+
input['a[]'] = arr;
|
|
1683
|
+
st.deepEqual(qs.parse(input), { a: ['x', 'y'] }, 'parses object input with bracket keys using existing array values');
|
|
1684
|
+
st.end();
|
|
1685
|
+
});
|
|
1686
|
+
|
|
1687
|
+
t.test('throws with singular message when object input bracket key exceeds arrayLimit of 1', function (st) {
|
|
1688
|
+
var input = {};
|
|
1689
|
+
var arr = ['x'];
|
|
1690
|
+
arr.a = ['z', 'w'];
|
|
1691
|
+
input['a[]'] = arr;
|
|
1692
|
+
st['throws'](
|
|
1693
|
+
function () {
|
|
1694
|
+
qs.parse(input, { throwOnLimitExceeded: true, arrayLimit: 1 });
|
|
1695
|
+
},
|
|
1696
|
+
new RangeError('Array limit exceeded. Only 1 element allowed in an array.'),
|
|
1697
|
+
'throws singular error for object input exceeding arrayLimit 1'
|
|
1698
|
+
);
|
|
1699
|
+
st.end();
|
|
1700
|
+
});
|
|
1701
|
+
|
|
1567
1702
|
t.end();
|
|
1568
1703
|
});
|
package/test/stringify.js
CHANGED
|
@@ -651,6 +651,49 @@ test('stringify()', function (t) {
|
|
|
651
651
|
st.end();
|
|
652
652
|
});
|
|
653
653
|
|
|
654
|
+
t.test('does not crash on null/undefined entries in arrayFormat=comma with encodeValuesOnly', function (st) {
|
|
655
|
+
st.doesNotThrow(
|
|
656
|
+
function () { qs.stringify({ a: [null, 'b'] }, { arrayFormat: 'comma', encodeValuesOnly: true }); },
|
|
657
|
+
'does not pass a raw null array entry to the encoder'
|
|
658
|
+
);
|
|
659
|
+
st.doesNotThrow(
|
|
660
|
+
function () { qs.stringify({ a: [undefined, 'b'] }, { arrayFormat: 'comma', encodeValuesOnly: true }); },
|
|
661
|
+
'does not pass a raw undefined array entry to the encoder'
|
|
662
|
+
);
|
|
663
|
+
st.doesNotThrow(
|
|
664
|
+
function () { qs.stringify({ a: [null] }, { arrayFormat: 'comma', encodeValuesOnly: true }); },
|
|
665
|
+
'does not crash on a single-null array'
|
|
666
|
+
);
|
|
667
|
+
|
|
668
|
+
st.equal(
|
|
669
|
+
qs.stringify({ a: [null, 'b'] }, { arrayFormat: 'comma', encodeValuesOnly: true }),
|
|
670
|
+
'a=,b',
|
|
671
|
+
'null entry joins as empty, comma stays unencoded under encodeValuesOnly'
|
|
672
|
+
);
|
|
673
|
+
st.equal(
|
|
674
|
+
qs.stringify({ a: [undefined, 'b'] }, { arrayFormat: 'comma', encodeValuesOnly: true }),
|
|
675
|
+
'a=,b',
|
|
676
|
+
'undefined entry joins as empty, comma stays unencoded under encodeValuesOnly'
|
|
677
|
+
);
|
|
678
|
+
st.equal(
|
|
679
|
+
qs.stringify({ a: [null] }, { arrayFormat: 'comma', encodeValuesOnly: true }),
|
|
680
|
+
'a=',
|
|
681
|
+
'single-null array stringifies as empty value'
|
|
682
|
+
);
|
|
683
|
+
st.equal(
|
|
684
|
+
qs.stringify({ a: [null] }, { arrayFormat: 'comma', encodeValuesOnly: true, strictNullHandling: true }),
|
|
685
|
+
'a',
|
|
686
|
+
'strictNullHandling drops the equals sign for a single-null array'
|
|
687
|
+
);
|
|
688
|
+
st.equal(
|
|
689
|
+
qs.stringify({ a: [null] }, { arrayFormat: 'comma', encodeValuesOnly: true, skipNulls: true }),
|
|
690
|
+
'',
|
|
691
|
+
'skipNulls drops a single-null array entirely'
|
|
692
|
+
);
|
|
693
|
+
|
|
694
|
+
st.end();
|
|
695
|
+
});
|
|
696
|
+
|
|
654
697
|
t.test('stringifies a null object', { skip: !hasProto }, function (st) {
|
|
655
698
|
st.equal(qs.stringify({ __proto__: null, a: 'b' }), 'a=b');
|
|
656
699
|
st.end();
|
|
@@ -825,6 +868,35 @@ test('stringify()', function (t) {
|
|
|
825
868
|
st.end();
|
|
826
869
|
});
|
|
827
870
|
|
|
871
|
+
t.test('skips null/undefined entries in filter=array', function (st) {
|
|
872
|
+
st.doesNotThrow(
|
|
873
|
+
function () { qs.stringify({ a: 'b', undefined: 'x' }, { filter: ['a', undefined] }); },
|
|
874
|
+
'does not pass a raw undefined filter entry to the encoder'
|
|
875
|
+
);
|
|
876
|
+
st.doesNotThrow(
|
|
877
|
+
function () { qs.stringify({ a: 'b', 'null': 'x' }, { filter: ['a', null] }); },
|
|
878
|
+
'does not pass a raw null filter entry to the encoder'
|
|
879
|
+
);
|
|
880
|
+
|
|
881
|
+
st.equal(
|
|
882
|
+
qs.stringify({ a: 'b', undefined: 'x', c: 'd' }, { filter: ['a', undefined, 'c'] }),
|
|
883
|
+
'a=b&c=d',
|
|
884
|
+
'undefined filter entry is skipped, remaining keys are kept'
|
|
885
|
+
);
|
|
886
|
+
st.equal(
|
|
887
|
+
qs.stringify({ a: 'b', 'null': 'x', c: 'd' }, { filter: ['a', null, 'c'] }),
|
|
888
|
+
'a=b&c=d',
|
|
889
|
+
'null filter entry is skipped, remaining keys are kept'
|
|
890
|
+
);
|
|
891
|
+
st.equal(
|
|
892
|
+
qs.stringify({ a: 'b', 'null': 'x' }, { filter: [null] }),
|
|
893
|
+
'',
|
|
894
|
+
'filter array containing only null yields empty string'
|
|
895
|
+
);
|
|
896
|
+
|
|
897
|
+
st.end();
|
|
898
|
+
});
|
|
899
|
+
|
|
828
900
|
t.test('supports custom representations when filter=function', function (st) {
|
|
829
901
|
var calls = 0;
|
|
830
902
|
var obj = { a: 'b', c: 'd', e: { f: new Date(1257894000000) } };
|
|
@@ -1111,6 +1183,28 @@ test('stringify()', function (t) {
|
|
|
1111
1183
|
st.end();
|
|
1112
1184
|
});
|
|
1113
1185
|
|
|
1186
|
+
t.test('strictNullHandling: applies the formatter to the encoded key (RFC1738)', function (st) {
|
|
1187
|
+
st.equal(
|
|
1188
|
+
qs.stringify(
|
|
1189
|
+
{ 'a b': null, 'c d': 'e f' },
|
|
1190
|
+
{ strictNullHandling: false, format: 'RFC1738' }
|
|
1191
|
+
),
|
|
1192
|
+
'a+b=&c+d=e+f',
|
|
1193
|
+
'without: as expected'
|
|
1194
|
+
);
|
|
1195
|
+
|
|
1196
|
+
st.equal(
|
|
1197
|
+
qs.stringify(
|
|
1198
|
+
{ 'a b': null, 'c d': 'e f' },
|
|
1199
|
+
{ strictNullHandling: true, format: 'RFC1738' }
|
|
1200
|
+
),
|
|
1201
|
+
'a+b&c+d=e+f',
|
|
1202
|
+
'with: as expected'
|
|
1203
|
+
);
|
|
1204
|
+
|
|
1205
|
+
st.end();
|
|
1206
|
+
});
|
|
1207
|
+
|
|
1114
1208
|
t.test('throws if an invalid charset is specified', function (st) {
|
|
1115
1209
|
st['throws'](function () {
|
|
1116
1210
|
qs.stringify({ a: 'b' }, { charset: 'foobar' });
|
|
@@ -1146,6 +1240,12 @@ test('stringify()', function (t) {
|
|
|
1146
1240
|
'adds the right sentinel when instructed to and the charset is iso-8859-1'
|
|
1147
1241
|
);
|
|
1148
1242
|
|
|
1243
|
+
st.equal(
|
|
1244
|
+
qs.stringify({ a: 1, b: 2 }, { charsetSentinel: true, delimiter: ';' }),
|
|
1245
|
+
'utf8=%E2%9C%93;a=1;b=2',
|
|
1246
|
+
'uses the configured delimiter after the sentinel'
|
|
1247
|
+
);
|
|
1248
|
+
|
|
1149
1249
|
st.end();
|
|
1150
1250
|
});
|
|
1151
1251
|
|
|
@@ -1188,6 +1288,15 @@ test('stringify()', function (t) {
|
|
|
1188
1288
|
};
|
|
1189
1289
|
|
|
1190
1290
|
st.deepEqual(qs.stringify({ KeY: 'vAlUe' }, { encoder: encoder }), 'key=VALUE');
|
|
1291
|
+
|
|
1292
|
+
var noopEncoder = function () { return 'x'; };
|
|
1293
|
+
noopEncoder();
|
|
1294
|
+
st['throws'](
|
|
1295
|
+
function () { encoder('x', noopEncoder, 'utf-8', 'unknown'); },
|
|
1296
|
+
'this should never happen! type: unknown',
|
|
1297
|
+
'encoder throws for unexpected type'
|
|
1298
|
+
);
|
|
1299
|
+
|
|
1191
1300
|
st.end();
|
|
1192
1301
|
});
|
|
1193
1302
|
|
|
@@ -1307,4 +1416,33 @@ test('stringifies empty keys', function (t) {
|
|
|
1307
1416
|
|
|
1308
1417
|
st.end();
|
|
1309
1418
|
});
|
|
1419
|
+
|
|
1420
|
+
t.test('round-trips keys containing percent-encoded bracket text', function (st) {
|
|
1421
|
+
var cases = [
|
|
1422
|
+
{ 'a%5Bb': 'c' },
|
|
1423
|
+
{ 'a%5Db': 'c' },
|
|
1424
|
+
{ 'a%255Bb': 'c' },
|
|
1425
|
+
{ 'a%255Db': 'c' },
|
|
1426
|
+
{ a: { 'b%5Bc': 'd' } },
|
|
1427
|
+
{ a: { 'b%255Bc': 'd' } },
|
|
1428
|
+
{ 'a%5B%255Bb': 'c' }
|
|
1429
|
+
];
|
|
1430
|
+
for (var i = 0; i < cases.length; i++) {
|
|
1431
|
+
st.deepEqual(
|
|
1432
|
+
qs.parse(qs.stringify(cases[i])),
|
|
1433
|
+
cases[i],
|
|
1434
|
+
'round-trips ' + JSON.stringify(cases[i])
|
|
1435
|
+
);
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
st.end();
|
|
1439
|
+
});
|
|
1440
|
+
|
|
1441
|
+
t.test('parses input containing percent-encoded bracket text without mangling', function (st) {
|
|
1442
|
+
st.deepEqual(qs.parse('a%25255Bb=c'), { 'a%255Bb': 'c' }, 'a%25255Bb decodes to a%255Bb, not a%5Bb');
|
|
1443
|
+
st.deepEqual(qs.parse('a%25255Db=c'), { 'a%255Db': 'c' }, 'a%25255Db decodes to a%255Db, not a%5Db');
|
|
1444
|
+
st.deepEqual(qs.parse('a%5Bb%25255Bc%5D=d'), { a: { 'b%255Bc': 'd' } }, 'nested %25255B decodes to %255B inside segment, not %5B');
|
|
1445
|
+
|
|
1446
|
+
st.end();
|
|
1447
|
+
});
|
|
1310
1448
|
});
|
package/test/utils.js
CHANGED
|
@@ -31,6 +31,7 @@ test('merge()', function (t) {
|
|
|
31
31
|
t.deepEqual(noOptionsNonObjectSource, { foo: 'baz', bar: true });
|
|
32
32
|
|
|
33
33
|
var func = function f() {};
|
|
34
|
+
func();
|
|
34
35
|
t.deepEqual(
|
|
35
36
|
utils.merge(func, { foo: 'bar' }),
|
|
36
37
|
[func, { foo: 'bar' }],
|
|
@@ -112,6 +113,15 @@ test('merge()', function (t) {
|
|
|
112
113
|
s2t.end();
|
|
113
114
|
});
|
|
114
115
|
|
|
116
|
+
st.test('merges overflow object into primitive with plainObjects', function (s2t) {
|
|
117
|
+
var overflow = utils.combine(['a'], 'b', 0, false);
|
|
118
|
+
s2t.ok(utils.isOverflow(overflow), 'overflow object is marked');
|
|
119
|
+
var merged = utils.merge('c', overflow, { plainObjects: true });
|
|
120
|
+
s2t.ok(utils.isOverflow(merged), 'result is also marked as overflow');
|
|
121
|
+
s2t.deepEqual(merged, { __proto__: null, 0: 'c', 1: 'a', 2: 'b' }, 'creates null-proto object with primitive at 0');
|
|
122
|
+
s2t.end();
|
|
123
|
+
});
|
|
124
|
+
|
|
115
125
|
st.test('merges overflow object with multiple values into primitive', function (s2t) {
|
|
116
126
|
// Create an overflow object via combine: 3 elements (indices 0-2) with limit 0
|
|
117
127
|
var overflow = utils.combine(['b', 'c'], 'd', 0, false);
|
|
@@ -128,6 +138,21 @@ test('merge()', function (t) {
|
|
|
128
138
|
s2t.end();
|
|
129
139
|
});
|
|
130
140
|
|
|
141
|
+
st.test('merges primitive into array that exceeds arrayLimit', function (s2t) {
|
|
142
|
+
var arr = ['a', 'b', 'c'];
|
|
143
|
+
var merged = utils.merge(arr, 'd', { arrayLimit: 1 });
|
|
144
|
+
s2t.ok(utils.isOverflow(merged), 'result is marked as overflow');
|
|
145
|
+
s2t.deepEqual(merged, { 0: 'a', 1: 'b', 2: 'c', 3: 'd' }, 'converts to overflow object with primitive appended');
|
|
146
|
+
s2t.end();
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
st.test('merges array into primitive that exceeds arrayLimit', function (s2t) {
|
|
150
|
+
var merged = utils.merge('a', ['b', 'c'], { arrayLimit: 1 });
|
|
151
|
+
s2t.ok(utils.isOverflow(merged), 'result is marked as overflow');
|
|
152
|
+
s2t.deepEqual(merged, { 0: 'a', 1: 'b', 2: 'c' }, 'converts to overflow object');
|
|
153
|
+
s2t.end();
|
|
154
|
+
});
|
|
155
|
+
|
|
131
156
|
st.end();
|
|
132
157
|
});
|
|
133
158
|
|
|
@@ -376,7 +401,9 @@ test('encode', function (t) {
|
|
|
376
401
|
});
|
|
377
402
|
|
|
378
403
|
test('isBuffer()', function (t) {
|
|
379
|
-
|
|
404
|
+
var fn = function () {};
|
|
405
|
+
fn();
|
|
406
|
+
forEach([null, undefined, true, false, '', 'abc', 42, 0, NaN, {}, [], fn, /a/g], function (x) {
|
|
380
407
|
t.equal(utils.isBuffer(x), false, inspect(x) + ' is not a buffer');
|
|
381
408
|
});
|
|
382
409
|
|
|
@@ -386,8 +413,9 @@ test('isBuffer()', function (t) {
|
|
|
386
413
|
var saferBuffer = SaferBuffer.from('abc');
|
|
387
414
|
t.equal(utils.isBuffer(saferBuffer), true, 'SaferBuffer instance is a buffer');
|
|
388
415
|
|
|
389
|
-
var buffer =
|
|
390
|
-
t.
|
|
416
|
+
var buffer = SaferBuffer.from('abc');
|
|
417
|
+
t.notEqual(saferBuffer, buffer, 'different buffer instances');
|
|
418
|
+
t.equal(utils.isBuffer(buffer), true, 'another Buffer instance is a buffer');
|
|
391
419
|
t.end();
|
|
392
420
|
});
|
|
393
421
|
|