Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: keep colons in HTTP node form body values on migration (#38861)

mengnanjiugaipeifensee2bc8f2c17da
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