Comparing version 6.11.0 to 6.11.1
@@ -1,2 +0,11 @@ | ||
## **6.11.0 | ||
## **6.11.1** | ||
- [Fix] `stringify`: encode comma values more consistently (#463) | ||
- [readme] add usage of `filter` option for injecting custom serialization, i.e. of custom types (#447) | ||
- [meta] remove extraneous code backticks (#457) | ||
- [meta] fix changelog markdown | ||
- [actions] update checkout action | ||
- [actions] restrict action permissions | ||
- [Dev Deps] update `@ljharb/eslint-config`, `aud`, `object-inspect`, `tape` | ||
## **6.11.0** | ||
- [New] [Fix] `stringify`: revert 0e903c0; add `commaRoundTrip` option (#442) | ||
@@ -241,3 +250,3 @@ - [readme] fix version badge | ||
- [Fix] `parse`: ignore `__proto__` keys (#428) | ||
- [Fix]` `utils.merge`: avoid a crash with a null target and a truthy non-array source | ||
- [Fix] `utils.merge`: avoid a crash with a null target and a truthy non-array source | ||
- [Fix] correctly parse nested arrays | ||
@@ -295,3 +304,3 @@ - [Fix] `stringify`: fix a crash with `strictNullHandling` and a custom `filter`/`serializeDate` (#279) | ||
- [Fix] `utils.merge`: avoid a crash with a null target and an array source | ||
- [Fix]` `utils.merge`: avoid a crash with a null target and a truthy non-array source | ||
- [Fix] `utils.merge`: avoid a crash with a null target and a truthy non-array source | ||
- [Fix] `stringify`: fix a crash with `strictNullHandling` and a custom `filter`/`serializeDate` (#279) | ||
@@ -325,3 +334,3 @@ - [Fix] `utils`: `merge`: fix crash when `source` is a truthy primitive & no options are provided | ||
- [Fix] `utils.merge`: avoid a crash with a null target and an array source | ||
- [Fix]` `utils.merge`: avoid a crash with a null target and a truthy non-array source | ||
- [Fix] `utils.merge`: avoid a crash with a null target and a truthy non-array source | ||
- [Fix] `stringify`: fix a crash with `strictNullHandling` and a custom `filter`/`serializeDate` (#279) | ||
@@ -413,3 +422,3 @@ - [Fix] `utils`: `merge`: fix crash when `source` is a truthy primitive & no options are provided | ||
## **6.1.2 | ||
## **6.1.2** | ||
- [Fix] follow `allowPrototypes` option during merge (#201, #200) | ||
@@ -416,0 +425,0 @@ - [Fix] chmod a-x |
@@ -22,3 +22,2 @@ 'use strict'; | ||
var isArray = Array.isArray; | ||
var split = String.prototype.split; | ||
var push = Array.prototype.push; | ||
@@ -125,10 +124,2 @@ var pushToArray = function (arr, valueOrArray) { | ||
var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder, charset, 'key', format); | ||
if (generateArrayPrefix === 'comma' && encodeValuesOnly) { | ||
var valuesArray = split.call(String(obj), ','); | ||
var valuesJoined = ''; | ||
for (var i = 0; i < valuesArray.length; ++i) { | ||
valuesJoined += (i === 0 ? '' : ',') + formatter(encoder(valuesArray[i], defaults.encoder, charset, 'value', format)); | ||
} | ||
return [formatter(keyValue) + (commaRoundTrip && isArray(obj) && valuesArray.length === 1 ? '[]' : '') + '=' + valuesJoined]; | ||
} | ||
return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder, charset, 'value', format))]; | ||
@@ -148,2 +139,5 @@ } | ||
// we need to join elements in | ||
if (encodeValuesOnly && encoder) { | ||
obj = utils.maybeMap(obj, encoder); | ||
} | ||
objKeys = [{ value: obj.length > 0 ? obj.join(',') || null : void undefined }]; | ||
@@ -181,3 +175,3 @@ } else if (isArray(filter)) { | ||
skipNulls, | ||
encoder, | ||
generateArrayPrefix === 'comma' && encodeValuesOnly && isArray(obj) ? null : encoder, | ||
filter, | ||
@@ -184,0 +178,0 @@ sort, |
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://github.com/ljharb/qs", | ||
"version": "6.11.0", | ||
"version": "6.11.1", | ||
"repository": { | ||
@@ -37,4 +37,4 @@ "type": "git", | ||
"devDependencies": { | ||
"@ljharb/eslint-config": "^21.0.0", | ||
"aud": "^2.0.0", | ||
"@ljharb/eslint-config": "^21.0.1", | ||
"aud": "^2.0.2", | ||
"browserify": "^16.5.2", | ||
@@ -51,7 +51,7 @@ "eclint": "^2.8.1", | ||
"nyc": "^10.3.2", | ||
"object-inspect": "^1.12.2", | ||
"object-inspect": "^1.12.3", | ||
"qs-iconv": "^1.0.4", | ||
"safe-publish-latest": "^2.0.0", | ||
"safer-buffer": "^2.1.2", | ||
"tape": "^5.5.3" | ||
"tape": "^5.6.3" | ||
}, | ||
@@ -58,0 +58,0 @@ "scripts": { |
@@ -501,2 +501,40 @@ # qs <sup>[![Version Badge][npm-version-svg]][package-url]</sup> | ||
You could also use `filter` to inject custom serialization for user defined types. Consider you're working with | ||
some api that expects query strings of the format for ranges: | ||
``` | ||
https://domain.com/endpoint?range=30...70 | ||
``` | ||
For which you model as: | ||
```javascript | ||
class Range { | ||
constructor(from, to) { | ||
this.from = from; | ||
this.to = to; | ||
} | ||
} | ||
``` | ||
You could _inject_ a custom serializer to handle values of this type: | ||
```javascript | ||
qs.stringify( | ||
{ | ||
range: new Range(30, 70), | ||
}, | ||
{ | ||
filter: (prefix, value) => { | ||
if (value instanceof Range) { | ||
return `${value.from}...${value.to}`; | ||
} | ||
// serialize the usual way | ||
return value; | ||
}, | ||
} | ||
); | ||
// range=30...70 | ||
``` | ||
### Handling of `null` values | ||
@@ -503,0 +541,0 @@ |
@@ -163,2 +163,9 @@ 'use strict'; | ||
st.test('array with multiple items with a comma inside', function (s2t) { | ||
s2t.equal(qs.stringify({ a: ['c,d', 'e'] }, { encodeValuesOnly: true, arrayFormat: 'comma' }), 'a=c%2Cd,e'); | ||
s2t.equal(qs.stringify({ a: ['c,d', 'e'] }, { arrayFormat: 'comma' }), 'a=c%2Cd%2Ce'); | ||
s2t.end(); | ||
}); | ||
st.end(); | ||
@@ -175,2 +182,40 @@ }); | ||
t.test('stringifies comma and empty array values', function (st) { | ||
st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'indices' }), 'a[0]=,&a[1]=&a[2]=c,d%'); | ||
st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'brackets' }), 'a[]=,&a[]=&a[]=c,d%'); | ||
st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'comma' }), 'a=,,,c,d%'); | ||
st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: false, arrayFormat: 'repeat' }), 'a=,&a=&a=c,d%'); | ||
st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: true, arrayFormat: 'indices' }), 'a[0]=%2C&a[1]=&a[2]=c%2Cd%25'); | ||
st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a[]=%2C&a[]=&a[]=c%2Cd%25'); | ||
st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: true, arrayFormat: 'comma' }), 'a=%2C,,c%2Cd%25'); | ||
st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: true, arrayFormat: 'repeat' }), 'a=%2C&a=&a=c%2Cd%25'); | ||
st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: false, arrayFormat: 'indices' }), 'a%5B0%5D=%2C&a%5B1%5D=&a%5B2%5D=c%2Cd%25'); | ||
st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: false, arrayFormat: 'brackets' }), 'a%5B%5D=%2C&a%5B%5D=&a%5B%5D=c%2Cd%25'); | ||
st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: false, arrayFormat: 'comma' }), 'a=%2C%2C%2Cc%2Cd%25'); | ||
st.equal(qs.stringify({ a: [',', '', 'c,d%'] }, { encode: true, encodeValuesOnly: false, arrayFormat: 'repeat' }), 'a=%2C&a=&a=c%2Cd%25'); | ||
st.end(); | ||
}); | ||
t.test('stringifies comma and empty non-array values', function (st) { | ||
st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: false, arrayFormat: 'indices' }), 'a=,&b=&c=c,d%'); | ||
st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: false, arrayFormat: 'brackets' }), 'a=,&b=&c=c,d%'); | ||
st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: false, arrayFormat: 'comma' }), 'a=,&b=&c=c,d%'); | ||
st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: false, arrayFormat: 'repeat' }), 'a=,&b=&c=c,d%'); | ||
st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: true, encodeValuesOnly: true, arrayFormat: 'indices' }), 'a=%2C&b=&c=c%2Cd%25'); | ||
st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: true, encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a=%2C&b=&c=c%2Cd%25'); | ||
st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: true, encodeValuesOnly: true, arrayFormat: 'comma' }), 'a=%2C&b=&c=c%2Cd%25'); | ||
st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: true, encodeValuesOnly: true, arrayFormat: 'repeat' }), 'a=%2C&b=&c=c%2Cd%25'); | ||
st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: true, encodeValuesOnly: false, arrayFormat: 'indices' }), 'a=%2C&b=&c=c%2Cd%25'); | ||
st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: true, encodeValuesOnly: false, arrayFormat: 'brackets' }), 'a=%2C&b=&c=c%2Cd%25'); | ||
st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: true, encodeValuesOnly: false, arrayFormat: 'comma' }), 'a=%2C&b=&c=c%2Cd%25'); | ||
st.equal(qs.stringify({ a: ',', b: '', c: 'c,d%' }, { encode: true, encodeValuesOnly: false, arrayFormat: 'repeat' }), 'a=%2C&b=&c=c%2Cd%25'); | ||
st.end(); | ||
}); | ||
t.test('stringifies a nested array value with dots notation', function (st) { | ||
@@ -177,0 +222,0 @@ st.equal( |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
234521
4188
664