From e2bc8f2c17da0713bcf0c2bd32a980c73d4d352f Mon Sep 17 00:00:00 2001 From: mengnanjiugaipeifense Date: Mon, 3 Aug 2026 16:39:04 +0800 Subject: [PATCH] fix: keep colons in HTTP node form body values on migration (#38861) Co-authored-by: xiaweiwei67-stack <293320877+xiaweiwei67-stack@users.noreply.github.com> Co-authored-by: Cursor Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- .../nodes/http/__tests__/utils.spec.ts | 47 +++++++++++++++++++ .../components/workflow/nodes/http/utils.ts | 4 +- 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 web/app/components/workflow/nodes/http/__tests__/utils.spec.ts diff --git a/web/app/components/workflow/nodes/http/__tests__/utils.spec.ts b/web/app/components/workflow/nodes/http/__tests__/utils.spec.ts new file mode 100644 index 00000000000..13d776246c0 --- /dev/null +++ b/web/app/components/workflow/nodes/http/__tests__/utils.spec.ts @@ -0,0 +1,47 @@ +import { BodyPayloadValueType } from '../types' +import { transformToBodyPayload } from '../utils' + +describe('transformToBodyPayload', () => { + // Bodies without a key (json, raw-text, binary) keep the raw string untouched. + describe('when hasKey is false', () => { + it('should keep the whole string as a single text value', () => { + const result = transformToBodyPayload('{"url":"https://a:1"}', false) + + expect(result).toEqual([{ type: BodyPayloadValueType.text, value: '{"url":"https://a:1"}' }]) + }) + }) + + // form-data / x-www-form-urlencoded bodies are stored as `key:value` lines. + describe('when hasKey is true', () => { + it('should split a simple key:value pair', () => { + const result = transformToBodyPayload('name:alice', true) + + expect(result).toEqual([{ key: 'name', type: BodyPayloadValueType.text, value: 'alice' }]) + }) + + it('should keep colons that belong to the value', () => { + const result = transformToBodyPayload('url:https://host:8080/path', true) + + expect(result[0]).toEqual({ + key: 'url', + type: BodyPayloadValueType.text, + value: 'https://host:8080/path', + }) + }) + + it('should parse each line independently', () => { + const result = transformToBodyPayload('a:1\nb:2:3', true) + + expect(result).toEqual([ + { key: 'a', type: BodyPayloadValueType.text, value: '1' }, + { key: 'b', type: BodyPayloadValueType.text, value: '2:3' }, + ]) + }) + + it('should use an empty value when the line has no colon', () => { + const result = transformToBodyPayload('lonelykey', true) + + expect(result).toEqual([{ key: 'lonelykey', type: BodyPayloadValueType.text, value: '' }]) + }) + }) +}) diff --git a/web/app/components/workflow/nodes/http/utils.ts b/web/app/components/workflow/nodes/http/utils.ts index 1d07fc53983..11b366e1984 100644 --- a/web/app/components/workflow/nodes/http/utils.ts +++ b/web/app/components/workflow/nodes/http/utils.ts @@ -11,11 +11,11 @@ export const transformToBodyPayload = (old: string, hasKey: boolean): BodyPayloa ] } const bodyPayload = old.split('\n').map((item) => { - const [key, value] = item.split(':') + const [key, ...others] = item.split(':') return { key: key || '', type: BodyPayloadValueType.text, - value: value || '', + value: others.join(':'), } }) return bodyPayload