qs 6.10.4 → 6.10.5
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/.eslintrc +1 -1
- package/CHANGELOG.md +3 -0
- package/dist/qs.js +5 -3
- package/lib/stringify.js +5 -3
- package/package.json +1 -1
- package/test/stringify.js +28 -11
package/.eslintrc
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
## **6.10.5**
|
|
2
|
+
- [Fix] `stringify`: with `arrayFormat: comma`, properly include an explicit `[]` on a single-item array (#434)
|
|
3
|
+
|
|
1
4
|
## **6.10.4**
|
|
2
5
|
- [Fix] `stringify`: with `arrayFormat: comma`, include an explicit `[]` on a single-item array (#441)
|
|
3
6
|
- [meta] use `npmignore` to autogenerate an npmignore file
|
package/dist/qs.js
CHANGED
|
@@ -430,7 +430,7 @@ var stringify = function stringify(
|
|
|
430
430
|
for (var i = 0; i < valuesArray.length; ++i) {
|
|
431
431
|
valuesJoined += (i === 0 ? '' : ',') + formatter(encoder(valuesArray[i], defaults.encoder, charset, 'value', format));
|
|
432
432
|
}
|
|
433
|
-
return [formatter(keyValue) + (
|
|
433
|
+
return [formatter(keyValue) + (isArray(obj) && valuesArray.length === 1 ? '[]' : '') + '=' + valuesJoined];
|
|
434
434
|
}
|
|
435
435
|
return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder, charset, 'value', format))];
|
|
436
436
|
}
|
|
@@ -454,6 +454,8 @@ var stringify = function stringify(
|
|
|
454
454
|
objKeys = sort ? keys.sort(sort) : keys;
|
|
455
455
|
}
|
|
456
456
|
|
|
457
|
+
var adjustedPrefix = generateArrayPrefix === 'comma' && isArray(obj) && obj.length === 1 ? prefix + '[]' : prefix;
|
|
458
|
+
|
|
457
459
|
for (var j = 0; j < objKeys.length; ++j) {
|
|
458
460
|
var key = objKeys[j];
|
|
459
461
|
var value = typeof key === 'object' && typeof key.value !== 'undefined' ? key.value : obj[key];
|
|
@@ -463,8 +465,8 @@ var stringify = function stringify(
|
|
|
463
465
|
}
|
|
464
466
|
|
|
465
467
|
var keyPrefix = isArray(obj)
|
|
466
|
-
? typeof generateArrayPrefix === 'function' ? generateArrayPrefix(
|
|
467
|
-
:
|
|
468
|
+
? typeof generateArrayPrefix === 'function' ? generateArrayPrefix(adjustedPrefix, key) : adjustedPrefix
|
|
469
|
+
: adjustedPrefix + (allowDots ? '.' + key : '[' + key + ']');
|
|
468
470
|
|
|
469
471
|
sideChannel.set(object, step);
|
|
470
472
|
var valueSideChannel = getSideChannel();
|
package/lib/stringify.js
CHANGED
|
@@ -126,7 +126,7 @@ var stringify = function stringify(
|
|
|
126
126
|
for (var i = 0; i < valuesArray.length; ++i) {
|
|
127
127
|
valuesJoined += (i === 0 ? '' : ',') + formatter(encoder(valuesArray[i], defaults.encoder, charset, 'value', format));
|
|
128
128
|
}
|
|
129
|
-
return [formatter(keyValue) + (
|
|
129
|
+
return [formatter(keyValue) + (isArray(obj) && valuesArray.length === 1 ? '[]' : '') + '=' + valuesJoined];
|
|
130
130
|
}
|
|
131
131
|
return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder, charset, 'value', format))];
|
|
132
132
|
}
|
|
@@ -150,6 +150,8 @@ var stringify = function stringify(
|
|
|
150
150
|
objKeys = sort ? keys.sort(sort) : keys;
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
+
var adjustedPrefix = generateArrayPrefix === 'comma' && isArray(obj) && obj.length === 1 ? prefix + '[]' : prefix;
|
|
154
|
+
|
|
153
155
|
for (var j = 0; j < objKeys.length; ++j) {
|
|
154
156
|
var key = objKeys[j];
|
|
155
157
|
var value = typeof key === 'object' && typeof key.value !== 'undefined' ? key.value : obj[key];
|
|
@@ -159,8 +161,8 @@ var stringify = function stringify(
|
|
|
159
161
|
}
|
|
160
162
|
|
|
161
163
|
var keyPrefix = isArray(obj)
|
|
162
|
-
? typeof generateArrayPrefix === 'function' ? generateArrayPrefix(
|
|
163
|
-
:
|
|
164
|
+
? typeof generateArrayPrefix === 'function' ? generateArrayPrefix(adjustedPrefix, key) : adjustedPrefix
|
|
165
|
+
: adjustedPrefix + (allowDots ? '.' + key : '[' + key + ']');
|
|
164
166
|
|
|
165
167
|
sideChannel.set(object, step);
|
|
166
168
|
var valueSideChannel = getSideChannel();
|
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.10.
|
|
5
|
+
"version": "6.10.5",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/ljharb/qs.git"
|
package/test/stringify.js
CHANGED
|
@@ -132,15 +132,32 @@ test('stringify()', function (t) {
|
|
|
132
132
|
});
|
|
133
133
|
|
|
134
134
|
t.test('stringifies an array value with one item vs multiple items', function (st) {
|
|
135
|
-
st.
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
135
|
+
st.test('non-array item', function (s2t) {
|
|
136
|
+
s2t.equal(qs.stringify({ a: 'c' }, { encodeValuesOnly: true, arrayFormat: 'indices' }), 'a=c');
|
|
137
|
+
s2t.equal(qs.stringify({ a: 'c' }, { encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a=c');
|
|
138
|
+
s2t.equal(qs.stringify({ a: 'c' }, { encodeValuesOnly: true, arrayFormat: 'comma' }), 'a=c');
|
|
139
|
+
s2t.equal(qs.stringify({ a: 'c' }, { encodeValuesOnly: true }), 'a=c');
|
|
139
140
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
st.
|
|
141
|
+
s2t.end();
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
st.test('array with a single item', function (s2t) {
|
|
145
|
+
s2t.equal(qs.stringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'indices' }), 'a[0]=c');
|
|
146
|
+
s2t.equal(qs.stringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a[]=c');
|
|
147
|
+
s2t.equal(qs.stringify({ a: ['c'] }, { encodeValuesOnly: true, arrayFormat: 'comma' }), 'a[]=c'); // so it parses back as an array
|
|
148
|
+
s2t.equal(qs.stringify({ a: ['c'] }, { encodeValuesOnly: true }), 'a[0]=c');
|
|
149
|
+
|
|
150
|
+
s2t.end();
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
st.test('array with multiple items', function (s2t) {
|
|
154
|
+
s2t.equal(qs.stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'indices' }), 'a[0]=c&a[1]=d');
|
|
155
|
+
s2t.equal(qs.stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'brackets' }), 'a[]=c&a[]=d');
|
|
156
|
+
s2t.equal(qs.stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true, arrayFormat: 'comma' }), 'a=c,d');
|
|
157
|
+
s2t.equal(qs.stringify({ a: ['c', 'd'] }, { encodeValuesOnly: true }), 'a[0]=c&a[1]=d');
|
|
158
|
+
|
|
159
|
+
s2t.end();
|
|
160
|
+
});
|
|
144
161
|
|
|
145
162
|
st.end();
|
|
146
163
|
});
|
|
@@ -362,12 +379,12 @@ test('stringify()', function (t) {
|
|
|
362
379
|
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'indices' }), 'b[0]=&c=c');
|
|
363
380
|
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'brackets' }), 'b[]=&c=c');
|
|
364
381
|
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'repeat' }), 'b=&c=c');
|
|
365
|
-
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'comma' }), 'b=&c=c');
|
|
382
|
+
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'comma' }), 'b[]=&c=c');
|
|
366
383
|
// with strictNullHandling
|
|
367
384
|
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'indices', strictNullHandling: true }), 'b[0]&c=c');
|
|
368
385
|
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'brackets', strictNullHandling: true }), 'b[]&c=c');
|
|
369
386
|
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'repeat', strictNullHandling: true }), 'b&c=c');
|
|
370
|
-
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'comma', strictNullHandling: true }), 'b&c=c');
|
|
387
|
+
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'comma', strictNullHandling: true }), 'b[]&c=c');
|
|
371
388
|
// with skipNulls
|
|
372
389
|
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'indices', skipNulls: true }), 'c=c');
|
|
373
390
|
st.equal(qs.stringify({ a: [], b: [null], c: 'c' }, { encode: false, arrayFormat: 'brackets', skipNulls: true }), 'c=c');
|
|
@@ -695,7 +712,7 @@ test('stringify()', function (t) {
|
|
|
695
712
|
arrayFormat: 'comma'
|
|
696
713
|
}
|
|
697
714
|
),
|
|
698
|
-
'a=' + date.getTime(),
|
|
715
|
+
'a%5B%5D=' + date.getTime(),
|
|
699
716
|
'works with arrayFormat comma'
|
|
700
717
|
);
|
|
701
718
|
|