Comparing version 6.10.4 to 6.10.5
@@ -0,1 +1,4 @@ | ||
## **6.10.5** | ||
- [Fix] `stringify`: with `arrayFormat: comma`, properly include an explicit `[]` on a single-item array (#434) | ||
## **6.10.4** | ||
@@ -2,0 +5,0 @@ - [Fix] `stringify`: with `arrayFormat: comma`, include an explicit `[]` on a single-item array (#441) |
@@ -129,3 +129,3 @@ 'use strict'; | ||
} | ||
return [formatter(keyValue) + (i === 1 ? '[]' : '') + '=' + valuesJoined]; | ||
return [formatter(keyValue) + (isArray(obj) && valuesArray.length === 1 ? '[]' : '') + '=' + valuesJoined]; | ||
} | ||
@@ -154,2 +154,4 @@ return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder, charset, 'value', format))]; | ||
var adjustedPrefix = generateArrayPrefix === 'comma' && isArray(obj) && obj.length === 1 ? prefix + '[]' : prefix; | ||
for (var j = 0; j < objKeys.length; ++j) { | ||
@@ -164,4 +166,4 @@ var key = objKeys[j]; | ||
var keyPrefix = isArray(obj) | ||
? typeof generateArrayPrefix === 'function' ? generateArrayPrefix(prefix, key) : prefix | ||
: prefix + (allowDots ? '.' + key : '[' + key + ']'); | ||
? typeof generateArrayPrefix === 'function' ? generateArrayPrefix(adjustedPrefix, key) : adjustedPrefix | ||
: adjustedPrefix + (allowDots ? '.' + key : '[' + key + ']'); | ||
@@ -168,0 +170,0 @@ sideChannel.set(object, step); |
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://github.com/ljharb/qs", | ||
"version": "6.10.4", | ||
"version": "6.10.5", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
@@ -135,12 +135,29 @@ 'use strict'; | ||
t.test('stringifies an array value with one item vs multiple items', function (st) { | ||
st.equal(qs.stringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'indices' }), 'a[0]=c'); | ||
st.equal(qs.stringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a[]=c'); | ||
st.equal(qs.stringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'comma' }), 'a[]=c'); // so it parses back as an array | ||
st.equal(qs.stringify({ a: ['c'] }, { encodeValuesOnly: true }), 'a[0]=c'); | ||
st.test('non-array item', function (s2t) { | ||
s2t.equal(qs.stringify({ a: 'c' }, { encodeValuesOnly: true, arrayFormat: 'indices' }), 'a=c'); | ||
s2t.equal(qs.stringify({ a: 'c' }, { encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a=c'); | ||
s2t.equal(qs.stringify({ a: 'c' }, { encodeValuesOnly: true, arrayFormat: 'comma' }), 'a=c'); | ||
s2t.equal(qs.stringify({ a: 'c' }, { encodeValuesOnly: true }), 'a=c'); | ||
st.equal(qs.stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'indices' }), 'a[0]=c&a[1]=d'); | ||
st.equal(qs.stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a[]=c&a[]=d'); | ||
st.equal(qs.stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'comma' }), 'a=c,d'); | ||
st.equal(qs.stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true }), 'a[0]=c&a[1]=d'); | ||
s2t.end(); | ||
}); | ||
st.test('array with a single item', function (s2t) { | ||
s2t.equal(qs.stringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'indices' }), 'a[0]=c'); | ||
s2t.equal(qs.stringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a[]=c'); | ||
s2t.equal(qs.stringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'comma' }), 'a[]=c'); // so it parses back as an array | ||
s2t.equal(qs.stringify({ a: ['c'] }, { encodeValuesOnly: true }), 'a[0]=c'); | ||
s2t.end(); | ||
}); | ||
st.test('array with multiple items', function (s2t) { | ||
s2t.equal(qs.stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'indices' }), 'a[0]=c&a[1]=d'); | ||
s2t.equal(qs.stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a[]=c&a[]=d'); | ||
s2t.equal(qs.stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'comma' }), 'a=c,d'); | ||
s2t.equal(qs.stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true }), 'a[0]=c&a[1]=d'); | ||
s2t.end(); | ||
}); | ||
st.end(); | ||
@@ -366,3 +383,3 @@ }); | ||
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'repeat' }), 'b=&c=c'); | ||
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'comma' }), 'b=&c=c'); | ||
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'comma' }), 'b[]=&c=c'); | ||
// with strictNullHandling | ||
@@ -372,3 +389,3 @@ st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'indices', strictNullHandling: true }), 'b[0]&c=c'); | ||
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'repeat', strictNullHandling: true }), 'b&c=c'); | ||
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'comma', strictNullHandling: true }), 'b&c=c'); | ||
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'comma', strictNullHandling: true }), 'b[]&c=c'); | ||
// with skipNulls | ||
@@ -701,3 +718,3 @@ st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'indices', skipNulls: true }), 'c=c'); | ||
), | ||
'a=' + date.getTime(), | ||
'a%5B%5D=' + date.getTime(), | ||
'works with arrayFormat comma' | ||
@@ -704,0 +721,0 @@ ); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
227634
4119
1