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(cli): accept BOM-prefixed JSON input (#44386)

mikad446b520a3b5
diff --git a/cli/src/call/input.test.ts b/cli/src/call/input.test.ts
index e8bb26ecaef..e6340846acf 100644
--- a/cli/src/call/input.test.ts
+++ b/cli/src/call/input.test.ts
@@ -45,6 +45,21 @@ const refs = (stdin: string, files: Record<string, string> = {}) => ({
},
})
+it('ignores a leading BOM in JSON input without changing string values', async () => {
+ expect(await loadInput(src('\uFEFF{"a":1}'))).toEqual({ a: 1 })
+ expect(await loadInput(src('@input.json', '', { 'input.json': '\uFEFF{"b":2}' }))).toEqual({
+ b: 2,
+ })
+ expect(await loadInput(src('@-', '\uFEFF{"c":3}'))).toEqual({ c: 3 })
+ expect(
+ await resolveFileRefs(
+ { inputs: '@inputs.json' },
+ REF_SCHEMA,
+ refs('', { 'inputs.json': '\uFEFF{"value":"inside\\uFEFF"}' }),
+ ),
+ ).toEqual({ inputs: { value: 'inside\uFEFF' } })
+})
+
it('resolves @file and @- only on non-scalar declared fields', async () => {
expect(
await resolveFileRefs(
diff --git a/cli/src/call/input.ts b/cli/src/call/input.ts
index ea68ff9c930..210cf357749 100644
--- a/cli/src/call/input.ts
+++ b/cli/src/call/input.ts
@@ -25,7 +25,7 @@ const STDIN_LABEL = 'stdin'
export function parseJsonValue(raw: string, source: string): unknown {
try {
- return JSON.parse(raw)
+ return JSON.parse(raw.startsWith('\uFEFF') ? raw.slice(1) : raw)
} catch (cause) {
throw inputInvalid(`${source}: not valid JSON (${errorMessage(cause)})`, cause)
}