Merge branch 'main' into next

This commit is contained in:
GitHub Actions Bot 2024-09-05 10:55:52 +00:00
commit 2c3d66a8fc
2 changed files with 25 additions and 4 deletions

View File

@ -8,6 +8,7 @@
*/
import axios, { AxiosRequestConfig } from 'axios';
import { trim } from 'lodash';
import { Processor, Instruction, JOB_STATUS, FlowNodeModel } from '@nocobase/plugin-workflow';
@ -38,14 +39,14 @@ async function request(config) {
// default headers
const { url, method = 'POST', contentType = 'application/json', data, timeout = 5000 } = config;
const headers = (config.headers ?? []).reduce((result, header) => {
const name = header.name?.trim();
const name = trim(header.name);
if (name.toLowerCase() === 'content-type') {
return result;
}
return Object.assign(result, { [name]: header.value?.trim() });
return Object.assign(result, { [name]: trim(header.value) });
}, {});
const params = (config.params ?? []).reduce(
(result, param) => Object.assign(result, { [param.name]: param.value?.trim() }),
(result, param) => Object.assign(result, { [param.name]: trim(param.value) }),
{},
);
@ -53,7 +54,7 @@ async function request(config) {
headers['Content-Type'] = contentType;
return axios.request({
url: url?.trim(),
url: trim(url),
method,
headers,
params,

View File

@ -143,6 +143,26 @@ describe('workflow > instructions > request', () => {
await app.destroy();
});
describe('params processing', () => {
it('trim should not crash', async () => {
await workflow.createNode({
type: 'request',
config: {
url: api.URL_DATA,
method: 'GET',
params: [{ name: 'id', value: '{{$context.data.id}}' }],
} as RequestConfig,
});
await PostRepo.create({ values: { title: 't1' } });
await sleep(500);
const [execution] = await workflow.getExecutions();
expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
});
});
describe('request static app routes', () => {
it('get data (legacy)', async () => {
await workflow.createNode({