qs 6.13.0 → 6.14.0
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 -0
- package/CHANGELOG.md +22 -0
- package/README.md +25 -1
- package/dist/qs.js +95 -44
- package/lib/parse.js +44 -12
- package/lib/stringify.js +11 -6
- package/lib/utils.js +7 -4
- package/package.json +9 -7
- package/test/parse.js +133 -27
- package/test/stringify.js +19 -11
- package/test/utils.js +126 -0
package/test/utils.js
CHANGED
|
@@ -4,6 +4,8 @@ var test = require('tape');
|
|
|
4
4
|
var inspect = require('object-inspect');
|
|
5
5
|
var SaferBuffer = require('safer-buffer').Buffer;
|
|
6
6
|
var forEach = require('for-each');
|
|
7
|
+
var v = require('es-value-fixtures');
|
|
8
|
+
|
|
7
9
|
var utils = require('../lib/utils');
|
|
8
10
|
|
|
9
11
|
test('merge()', function (t) {
|
|
@@ -28,6 +30,20 @@ test('merge()', function (t) {
|
|
|
28
30
|
var noOptionsNonObjectSource = utils.merge({ foo: 'baz' }, 'bar');
|
|
29
31
|
t.deepEqual(noOptionsNonObjectSource, { foo: 'baz', bar: true });
|
|
30
32
|
|
|
33
|
+
var func = function f() {};
|
|
34
|
+
t.deepEqual(
|
|
35
|
+
utils.merge(func, { foo: 'bar' }),
|
|
36
|
+
[func, { foo: 'bar' }],
|
|
37
|
+
'functions can not be merged into'
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
func.bar = 'baz';
|
|
41
|
+
t.deepEqual(
|
|
42
|
+
utils.merge({ foo: 'bar' }, func),
|
|
43
|
+
{ foo: 'bar', bar: 'baz' },
|
|
44
|
+
'functions can be merge sources'
|
|
45
|
+
);
|
|
46
|
+
|
|
31
47
|
t.test(
|
|
32
48
|
'avoids invoking array setters unnecessarily',
|
|
33
49
|
{ skip: typeof Object.defineProperty !== 'function' },
|
|
@@ -119,6 +135,104 @@ test('combine()', function (t) {
|
|
|
119
135
|
t.end();
|
|
120
136
|
});
|
|
121
137
|
|
|
138
|
+
test('decode', function (t) {
|
|
139
|
+
t.equal(
|
|
140
|
+
utils.decode('a+b'),
|
|
141
|
+
'a b',
|
|
142
|
+
'decodes + to space'
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
t.equal(
|
|
146
|
+
utils.decode('name%2Eobj'),
|
|
147
|
+
'name.obj',
|
|
148
|
+
'decodes a string'
|
|
149
|
+
);
|
|
150
|
+
t.equal(
|
|
151
|
+
utils.decode('name%2Eobj%2Efoo', null, 'iso-8859-1'),
|
|
152
|
+
'name.obj.foo',
|
|
153
|
+
'decodes a string in iso-8859-1'
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
t.end();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('encode', function (t) {
|
|
160
|
+
forEach(v.nullPrimitives, function (nullish) {
|
|
161
|
+
t['throws'](
|
|
162
|
+
function () { utils.encode(nullish); },
|
|
163
|
+
TypeError,
|
|
164
|
+
inspect(nullish) + ' is not a string'
|
|
165
|
+
);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
t.equal(utils.encode(''), '', 'empty string returns itself');
|
|
169
|
+
t.deepEqual(utils.encode([]), [], 'empty array returns itself');
|
|
170
|
+
t.deepEqual(utils.encode({ length: 0 }), { length: 0 }, 'empty arraylike returns itself');
|
|
171
|
+
|
|
172
|
+
t.test('symbols', { skip: !v.hasSymbols }, function (st) {
|
|
173
|
+
st.equal(utils.encode(Symbol('x')), 'Symbol%28x%29', 'symbol is encoded');
|
|
174
|
+
|
|
175
|
+
st.end();
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
t.equal(
|
|
179
|
+
utils.encode('(abc)'),
|
|
180
|
+
'%28abc%29',
|
|
181
|
+
'encodes parentheses'
|
|
182
|
+
);
|
|
183
|
+
t.equal(
|
|
184
|
+
utils.encode({ toString: function () { return '(abc)'; } }),
|
|
185
|
+
'%28abc%29',
|
|
186
|
+
'toStrings and encodes parentheses'
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
t.equal(
|
|
190
|
+
utils.encode('abc 123 💩', null, 'iso-8859-1'),
|
|
191
|
+
'abc%20123%20%26%2355357%3B%26%2356489%3B',
|
|
192
|
+
'encodes in iso-8859-1'
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
var longString = '';
|
|
196
|
+
var expectedString = '';
|
|
197
|
+
for (var i = 0; i < 1500; i++) {
|
|
198
|
+
longString += ' ';
|
|
199
|
+
expectedString += '%20';
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
t.equal(
|
|
203
|
+
utils.encode(longString),
|
|
204
|
+
expectedString,
|
|
205
|
+
'encodes a long string'
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
t.equal(
|
|
209
|
+
utils.encode('\x28\x29'),
|
|
210
|
+
'%28%29',
|
|
211
|
+
'encodes parens normally'
|
|
212
|
+
);
|
|
213
|
+
t.equal(
|
|
214
|
+
utils.encode('\x28\x29', null, null, null, 'RFC1738'),
|
|
215
|
+
'()',
|
|
216
|
+
'does not encode parens in RFC1738'
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
// todo RFC1738 format
|
|
220
|
+
|
|
221
|
+
t.equal(
|
|
222
|
+
utils.encode('Āက豈'),
|
|
223
|
+
'%C4%80%E1%80%80%EF%A4%80',
|
|
224
|
+
'encodes multibyte chars'
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
t.equal(
|
|
228
|
+
utils.encode('\uD83D \uDCA9'),
|
|
229
|
+
'%F0%9F%90%A0%F0%BA%90%80',
|
|
230
|
+
'encodes lone surrogates'
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
t.end();
|
|
234
|
+
});
|
|
235
|
+
|
|
122
236
|
test('isBuffer()', function (t) {
|
|
123
237
|
forEach([null, undefined, true, false, '', 'abc', 42, 0, NaN, {}, [], function () {}, /a/g], function (x) {
|
|
124
238
|
t.equal(utils.isBuffer(x), false, inspect(x) + ' is not a buffer');
|
|
@@ -134,3 +248,15 @@ test('isBuffer()', function (t) {
|
|
|
134
248
|
t.equal(utils.isBuffer(buffer), true, 'real Buffer instance is a buffer');
|
|
135
249
|
t.end();
|
|
136
250
|
});
|
|
251
|
+
|
|
252
|
+
test('isRegExp()', function (t) {
|
|
253
|
+
t.equal(utils.isRegExp(/a/g), true, 'RegExp is a RegExp');
|
|
254
|
+
t.equal(utils.isRegExp(new RegExp('a', 'g')), true, 'new RegExp is a RegExp');
|
|
255
|
+
t.equal(utils.isRegExp(new Date()), false, 'Date is not a RegExp');
|
|
256
|
+
|
|
257
|
+
forEach(v.primitives, function (primitive) {
|
|
258
|
+
t.equal(utils.isRegExp(primitive), false, inspect(primitive) + ' is not a RegExp');
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
t.end();
|
|
262
|
+
});
|