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 <cursoragent@cursor.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
mengnanjiugaipeifense 2026-08-03 16:39:04 +08:00 committed by GitHub
parent dc8dd09450
commit e2bc8f2c17
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 49 additions and 2 deletions

View File

@ -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: '' }])
})
})
})

View File

@ -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