fix: encode url params (#4055)

This commit is contained in:
chenos 2024-04-18 14:52:31 +05:30 committed by GitHub
parent 52d00aef58
commit 78ea107edb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 1 deletions

View File

@ -177,6 +177,32 @@ describe('utils', () => {
});
});
it('decode associatedIndex', () => {
const params = parseRequest({
path: '/posts/a%2Fab/comments',
method: 'POST',
});
expect(params).toMatchObject({
resourceName: 'comments',
associatedName: 'posts',
associatedIndex: 'a/ab',
actionName: 'create',
});
});
it('decode path', () => {
const params = parseRequest({
path: '/posts/%25E7%259A%2584%25E6%25B3%2595%252F%25E5%259B%25BD%25E9%2598%259F/comments',
method: 'POST',
});
expect(params).toMatchObject({
resourceName: 'comments',
associatedName: 'posts',
associatedIndex: '的法/国队',
actionName: 'create',
});
});
it('store action', () => {
const params = parseRequest({
path: '/posts/1/comments',

View File

@ -189,6 +189,10 @@ export function parseRequest(request: ParseRequest, options: ParseOptions = {}):
}
}
if (params.associatedIndex) {
params.associatedIndex = decodeURIComponent(params.associatedIndex);
}
return params;
}

View File

@ -320,7 +320,7 @@ export class APIClient {
const target = {};
const handler = {
get: (_: any, actionName: string) => {
let url = name.split('.').join(`/${of || '_'}/`);
let url = name.split('.').join(`/${encodeURIComponent(of) || '_'}/`);
url += `:${actionName}`;
const config: AxiosRequestConfig = { url };
if (['get', 'list'].includes(actionName)) {