From c802056d4409e75477d2e957babb40dd30bbfce0 Mon Sep 17 00:00:00 2001 From: Anwarul Islam Date: Thu, 20 Feb 2025 16:59:43 +0600 Subject: [PATCH] fix: request validation issue on load persistence tab (#4759) Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com> --- .../src/components/http/BodyParameters.vue | 3 ++- packages/hoppscotch-data/src/rest/v/9.ts | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/hoppscotch-common/src/components/http/BodyParameters.vue b/packages/hoppscotch-common/src/components/http/BodyParameters.vue index b9c47492..afc2ca34 100644 --- a/packages/hoppscotch-common/src/components/http/BodyParameters.vue +++ b/packages/hoppscotch-common/src/components/http/BodyParameters.vue @@ -113,8 +113,9 @@ {{ file.name }} + {{ file.name }} + diff --git a/packages/hoppscotch-data/src/rest/v/9.ts b/packages/hoppscotch-data/src/rest/v/9.ts index ede23c41..deba3c6f 100644 --- a/packages/hoppscotch-data/src/rest/v/9.ts +++ b/packages/hoppscotch-data/src/rest/v/9.ts @@ -20,7 +20,7 @@ export const FormDataKeyValue = z z.union([ z.object({ isFile: z.literal(true), - value: z.array(z.instanceof(Blob).nullable()), + value: z.array(z.instanceof(Blob).nullable()).catch([]), }), z.object({ isFile: z.literal(false), @@ -28,6 +28,19 @@ export const FormDataKeyValue = z }), ]) ) + .transform((data) => { + // Sample use case about restoring the `value` field in an empty state during page reload + // for files chosen in the previous attempt + if (data.isFile && Array.isArray(data.value) && data.value.length === 0) { + return { + ...data, + isFile: false, + value: "", + } + } + + return data + }) export type FormDataKeyValue = z.infer