mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
Merge pull request #49 from maxhoffmann/master
Fixing arrays in get params
This commit is contained in:
@@ -8,7 +8,9 @@ function encode(val) {
|
|||||||
replace(/%3A/gi, ':').
|
replace(/%3A/gi, ':').
|
||||||
replace(/%24/g, '$').
|
replace(/%24/g, '$').
|
||||||
replace(/%2C/gi, ',').
|
replace(/%2C/gi, ',').
|
||||||
replace(/%20/g, '+');
|
replace(/%20/g, '+').
|
||||||
|
replace(/%5B/gi, '[').
|
||||||
|
replace(/%5D/gi, ']');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,6 +31,11 @@ module.exports = function buildUrl(url, params) {
|
|||||||
if (val === null || typeof val === 'undefined') {
|
if (val === null || typeof val === 'undefined') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (utils.isArray(val)) {
|
||||||
|
key = key + '[]';
|
||||||
|
}
|
||||||
|
|
||||||
if (!utils.isArray(val)) {
|
if (!utils.isArray(val)) {
|
||||||
val = [val];
|
val = [val];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ describe('helpers::buildUrl', function () {
|
|||||||
it('should support array params', function () {
|
it('should support array params', function () {
|
||||||
expect(buildUrl('/foo', {
|
expect(buildUrl('/foo', {
|
||||||
foo: ['bar', 'baz']
|
foo: ['bar', 'baz']
|
||||||
})).toEqual('/foo?foo=bar&foo=baz');
|
})).toEqual('/foo?foo[]=bar&foo[]=baz');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support special char params', function () {
|
it('should support special char params', function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user