NUEVA BUSQUEDA DE DATOS SRI
This commit is contained in:
181
node_modules/qs/test/parse.js
generated
vendored
181
node_modules/qs/test/parse.js
generated
vendored
@@ -32,6 +32,38 @@ test('parse()', function (t) {
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('arrayFormat: brackets allows only explicit arrays', function (st) {
|
||||
st.deepEqual(qs.parse('a[]=b&a[]=c', { arrayFormat: 'brackets' }), { a: ['b', 'c'] });
|
||||
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayFormat: 'brackets' }), { a: ['b', 'c'] });
|
||||
st.deepEqual(qs.parse('a=b,c', { arrayFormat: 'brackets' }), { a: 'b,c' });
|
||||
st.deepEqual(qs.parse('a=b&a=c', { arrayFormat: 'brackets' }), { a: ['b', 'c'] });
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('arrayFormat: indices allows only indexed arrays', function (st) {
|
||||
st.deepEqual(qs.parse('a[]=b&a[]=c', { arrayFormat: 'indices' }), { a: ['b', 'c'] });
|
||||
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayFormat: 'indices' }), { a: ['b', 'c'] });
|
||||
st.deepEqual(qs.parse('a=b,c', { arrayFormat: 'indices' }), { a: 'b,c' });
|
||||
st.deepEqual(qs.parse('a=b&a=c', { arrayFormat: 'indices' }), { a: ['b', 'c'] });
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('arrayFormat: comma allows only comma-separated arrays', function (st) {
|
||||
st.deepEqual(qs.parse('a[]=b&a[]=c', { arrayFormat: 'comma' }), { a: ['b', 'c'] });
|
||||
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayFormat: 'comma' }), { a: ['b', 'c'] });
|
||||
st.deepEqual(qs.parse('a=b,c', { arrayFormat: 'comma' }), { a: 'b,c' });
|
||||
st.deepEqual(qs.parse('a=b&a=c', { arrayFormat: 'comma' }), { a: ['b', 'c'] });
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('arrayFormat: repeat allows only repeated values', function (st) {
|
||||
st.deepEqual(qs.parse('a[]=b&a[]=c', { arrayFormat: 'repeat' }), { a: ['b', 'c'] });
|
||||
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayFormat: 'repeat' }), { a: ['b', 'c'] });
|
||||
st.deepEqual(qs.parse('a=b,c', { arrayFormat: 'repeat' }), { a: 'b,c' });
|
||||
st.deepEqual(qs.parse('a=b&a=c', { arrayFormat: 'repeat' }), { a: ['b', 'c'] });
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('allows enabling dot notation', function (st) {
|
||||
st.deepEqual(qs.parse('a.b=c'), { 'a.b': 'c' });
|
||||
st.deepEqual(qs.parse('a.b=c', { allowDots: true }), { a: { b: 'c' } });
|
||||
@@ -52,6 +84,18 @@ test('parse()', function (t) {
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('uses original key when depth = 0', function (st) {
|
||||
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { depth: 0 }), { 'a[0]': 'b', 'a[1]': 'c' });
|
||||
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' });
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('uses original key when depth = false', function (st) {
|
||||
st.deepEqual(qs.parse('a[0]=b&a[1]=c', { depth: false }), { 'a[0]': 'b', 'a[1]': 'c' });
|
||||
st.deepEqual(qs.parse('a[0][0]=b&a[0][1]=c&a[1]=d&e=2', { depth: false }), { 'a[0][0]': 'b', 'a[0][1]': 'c', 'a[1]': 'd', e: '2' });
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.deepEqual(qs.parse('a=b&a=c'), { a: ['b', 'c'] }, 'parses a simple array');
|
||||
|
||||
t.test('parses an explicit array', function (st) {
|
||||
@@ -96,6 +140,9 @@ test('parse()', function (t) {
|
||||
t.test('limits specific array indices to arrayLimit', function (st) {
|
||||
st.deepEqual(qs.parse('a[20]=a', { arrayLimit: 20 }), { a: ['a'] });
|
||||
st.deepEqual(qs.parse('a[21]=a', { arrayLimit: 20 }), { a: { 21: 'a' } });
|
||||
|
||||
st.deepEqual(qs.parse('a[20]=a'), { a: ['a'] });
|
||||
st.deepEqual(qs.parse('a[21]=a'), { a: { 21: 'a' } });
|
||||
st.end();
|
||||
});
|
||||
|
||||
@@ -225,6 +272,15 @@ test('parse()', function (t) {
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('parses sparse arrays', function (st) {
|
||||
/* eslint no-sparse-arrays: 0 */
|
||||
st.deepEqual(qs.parse('a[4]=1&a[1]=2', { allowSparse: true }), { a: [, '2', , , '1'] });
|
||||
st.deepEqual(qs.parse('a[1][b][2][c]=1', { allowSparse: true }), { a: [, { b: [, , { c: '1' }] }] });
|
||||
st.deepEqual(qs.parse('a[1][2][3][c]=1', { allowSparse: true }), { a: [, [, , [, , , { c: '1' }]]] });
|
||||
st.deepEqual(qs.parse('a[1][2][3][c][1]=1', { allowSparse: true }), { a: [, [, , [, , , { c: [, '1'] }]]] });
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('parses semi-parsed strings', function (st) {
|
||||
st.deepEqual(qs.parse({ 'a[b]': 'c' }), { a: { b: 'c' } });
|
||||
st.deepEqual(qs.parse({ 'a[b]': 'c', 'a[d]': 'e' }), { a: { b: 'c', d: 'e' } });
|
||||
@@ -325,6 +381,7 @@ test('parse()', function (t) {
|
||||
st.deepEqual(qs.parse('?foo=bar', { ignoreQueryPrefix: true }), { foo: 'bar' });
|
||||
st.deepEqual(qs.parse('foo=bar', { ignoreQueryPrefix: true }), { foo: 'bar' });
|
||||
st.deepEqual(qs.parse('?foo=bar', { ignoreQueryPrefix: false }), { '?foo': 'bar' });
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
@@ -353,6 +410,53 @@ test('parse()', function (t) {
|
||||
st.deepEqual(qs.parse('foo=', { comma: true }), { foo: '' });
|
||||
st.deepEqual(qs.parse('foo', { comma: true }), { foo: '' });
|
||||
st.deepEqual(qs.parse('foo', { comma: true, strictNullHandling: true }), { foo: null });
|
||||
|
||||
// test cases inversed from from stringify tests
|
||||
st.deepEqual(qs.parse('a[0]=c'), { a: ['c'] });
|
||||
st.deepEqual(qs.parse('a[]=c'), { a: ['c'] });
|
||||
st.deepEqual(qs.parse('a[]=c', { comma: true }), { a: ['c'] });
|
||||
|
||||
st.deepEqual(qs.parse('a[0]=c&a[1]=d'), { a: ['c', 'd'] });
|
||||
st.deepEqual(qs.parse('a[]=c&a[]=d'), { a: ['c', 'd'] });
|
||||
st.deepEqual(qs.parse('a=c,d', { comma: true }), { a: ['c', 'd'] });
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('parses values with comma as array divider', function (st) {
|
||||
st.deepEqual(qs.parse({ foo: 'bar,tee' }, { comma: false }), { foo: 'bar,tee' });
|
||||
st.deepEqual(qs.parse({ foo: 'bar,tee' }, { comma: true }), { foo: ['bar', 'tee'] });
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('use number decoder, parses string that has one number with comma option enabled', function (st) {
|
||||
var decoder = function (str, defaultDecoder, charset, type) {
|
||||
if (!isNaN(Number(str))) {
|
||||
return parseFloat(str);
|
||||
}
|
||||
return defaultDecoder(str, defaultDecoder, charset, type);
|
||||
};
|
||||
|
||||
st.deepEqual(qs.parse('foo=1', { comma: true, decoder: decoder }), { foo: 1 });
|
||||
st.deepEqual(qs.parse('foo=0', { comma: true, decoder: decoder }), { foo: 0 });
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('parses brackets holds array of arrays when having two parts of strings with comma as array divider', function (st) {
|
||||
st.deepEqual(qs.parse('foo[]=1,2,3&foo[]=4,5,6', { comma: true }), { foo: [['1', '2', '3'], ['4', '5', '6']] });
|
||||
st.deepEqual(qs.parse('foo[]=1,2,3&foo[]=', { comma: true }), { foo: [['1', '2', '3'], ''] });
|
||||
st.deepEqual(qs.parse('foo[]=1,2,3&foo[]=,', { comma: true }), { foo: [['1', '2', '3'], ['', '']] });
|
||||
st.deepEqual(qs.parse('foo[]=1,2,3&foo[]=a', { comma: true }), { foo: [['1', '2', '3'], 'a'] });
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('parses comma delimited array while having percent-encoded comma treated as normal text', function (st) {
|
||||
st.deepEqual(qs.parse('foo=a%2Cb', { comma: true }), { foo: 'a,b' });
|
||||
st.deepEqual(qs.parse('foo=a%2C%20b,d', { comma: true }), { foo: ['a, b', 'd'] });
|
||||
st.deepEqual(qs.parse('foo=a%2C%20b,c%2C%20d', { comma: true }), { foo: ['a, b', 'c, d'] });
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
@@ -532,13 +636,73 @@ test('parse()', function (t) {
|
||||
|
||||
st.deepEqual(
|
||||
qs.parse('a[b]=c&a=toString', { plainObjects: true }),
|
||||
{ a: { b: 'c', toString: true } },
|
||||
{ __proto__: null, a: { __proto__: null, b: 'c', toString: true } },
|
||||
'can overwrite prototype with plainObjects true'
|
||||
);
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('dunder proto is ignored', function (st) {
|
||||
var payload = 'categories[__proto__]=login&categories[__proto__]&categories[length]=42';
|
||||
var result = qs.parse(payload, { allowPrototypes: true });
|
||||
|
||||
st.deepEqual(
|
||||
result,
|
||||
{
|
||||
categories: {
|
||||
length: '42'
|
||||
}
|
||||
},
|
||||
'silent [[Prototype]] payload'
|
||||
);
|
||||
|
||||
var plainResult = qs.parse(payload, { allowPrototypes: true, plainObjects: true });
|
||||
|
||||
st.deepEqual(
|
||||
plainResult,
|
||||
{
|
||||
__proto__: null,
|
||||
categories: {
|
||||
__proto__: null,
|
||||
length: '42'
|
||||
}
|
||||
},
|
||||
'silent [[Prototype]] payload: plain objects'
|
||||
);
|
||||
|
||||
var query = qs.parse('categories[__proto__]=cats&categories[__proto__]=dogs&categories[some][json]=toInject', { allowPrototypes: true });
|
||||
|
||||
st.notOk(Array.isArray(query.categories), 'is not an array');
|
||||
st.notOk(query.categories instanceof Array, 'is not instanceof an array');
|
||||
st.deepEqual(query.categories, { some: { json: 'toInject' } });
|
||||
st.equal(JSON.stringify(query.categories), '{"some":{"json":"toInject"}}', 'stringifies as a non-array');
|
||||
|
||||
st.deepEqual(
|
||||
qs.parse('foo[__proto__][hidden]=value&foo[bar]=stuffs', { allowPrototypes: true }),
|
||||
{
|
||||
foo: {
|
||||
bar: 'stuffs'
|
||||
}
|
||||
},
|
||||
'hidden values'
|
||||
);
|
||||
|
||||
st.deepEqual(
|
||||
qs.parse('foo[__proto__][hidden]=value&foo[bar]=stuffs', { allowPrototypes: true, plainObjects: true }),
|
||||
{
|
||||
__proto__: null,
|
||||
foo: {
|
||||
__proto__: null,
|
||||
bar: 'stuffs'
|
||||
}
|
||||
},
|
||||
'hidden values: plain objects'
|
||||
);
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('can return null objects', { skip: !Object.create }, function (st) {
|
||||
var expected = Object.create(null);
|
||||
expected.a = Object.create(null);
|
||||
@@ -672,5 +836,20 @@ test('parse()', function (t) {
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('allows for decoding keys and values differently', function (st) {
|
||||
var decoder = function (str, defaultDecoder, charset, type) {
|
||||
if (type === 'key') {
|
||||
return defaultDecoder(str, defaultDecoder, charset, type).toLowerCase();
|
||||
}
|
||||
if (type === 'value') {
|
||||
return defaultDecoder(str, defaultDecoder, charset, type).toUpperCase();
|
||||
}
|
||||
throw 'this should never happen! type: ' + type;
|
||||
};
|
||||
|
||||
st.deepEqual(qs.parse('KeY=vAlUe', { decoder: decoder }), { key: 'VALUE' });
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user