Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(params): re-added the ability to set the function as paramsSerializer config; #5633

Merged
merged 17 commits into from Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
3f2f496
chore(ci): Add release-it script;
DigitalBrainJS Dec 10, 2022
1bfc41b
Merge branch 'chore/release-it' into v1.x
DigitalBrainJS Dec 10, 2022
acaf0f4
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 15, 2022
8a5de86
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 15, 2022
cff9271
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 17, 2022
67afe20
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 19, 2022
dc7b66d
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 22, 2022
716eb59
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 23, 2022
10216bf
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 29, 2022
3b199f4
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Jan 7, 2023
f3d444f
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Jan 19, 2023
077c381
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Jan 26, 2023
f598657
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Jan 31, 2023
7bf5713
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Feb 5, 2023
81a8bd6
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Mar 8, 2023
f8bb158
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Apr 5, 2023
b331bb1
fix(params): re-added the ability to set the function as `paramsSeria…
DigitalBrainJS Apr 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.d.cts
Expand Up @@ -370,7 +370,7 @@ declare namespace axios {
transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
headers?: (RawAxiosRequestHeaders & MethodsHeaders) | AxiosHeaders;
params?: any;
paramsSerializer?: ParamsSerializerOptions;
paramsSerializer?: ParamsSerializerOptions | CustomParamsSerializer;
data?: D;
timeout?: Milliseconds;
timeoutErrorMessage?: string;
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Expand Up @@ -311,7 +311,7 @@ export interface AxiosRequestConfig<D = any> {
transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
headers?: (RawAxiosRequestHeaders & MethodsHeaders) | AxiosHeaders;
params?: any;
paramsSerializer?: ParamsSerializerOptions;
paramsSerializer?: ParamsSerializerOptions | CustomParamsSerializer;
data?: D;
timeout?: Milliseconds;
timeoutErrorMessage?: string;
Expand Down
16 changes: 11 additions & 5 deletions lib/core/Axios.js
Expand Up @@ -57,11 +57,17 @@ class Axios {
}, false);
}

if (paramsSerializer !== undefined) {
validator.assertOptions(paramsSerializer, {
encode: validators.function,
serialize: validators.function
}, true);
if (paramsSerializer != null) {
if (utils.isFunction(paramsSerializer)) {
config.paramsSerializer = {
serialize: paramsSerializer
}
} else {
validator.assertOptions(paramsSerializer, {
encode: validators.function,
serialize: validators.function
}, true);
}
}

// Set config.method
Expand Down
14 changes: 14 additions & 0 deletions test/unit/adapters/http.js
Expand Up @@ -2103,4 +2103,18 @@
it('should properly handle synchronous errors inside the adapter', function () {
return assert.rejects(() => axios.get('http://192.168.0.285'), /Invalid URL/);
});

it('should support function as paramsSerializer value', async () => {
server = await startHTTPServer((req, res) => res.end(req.url));
Dismissed Show dismissed Hide dismissed

const {data} = await axios.post(LOCAL_SERVER_URL, 'test', {
params: {
x: 1
},
paramsSerializer: () => 'foo',
maxRedirects: 0
});

assert.strictEqual(data, '/?foo');
});
});