From b6e0fe105ba21eadcc4812f10d909084bd5a8393 Mon Sep 17 00:00:00 2001 From: tintinthong Date: Mon, 4 Nov 2024 21:20:46 +0800 Subject: [PATCH] accidentally removed original fix haha --- packages/runtime-common/query.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/packages/runtime-common/query.ts b/packages/runtime-common/query.ts index 79ba4340f3..c91b182fca 100644 --- a/packages/runtime-common/query.ts +++ b/packages/runtime-common/query.ts @@ -429,3 +429,34 @@ export function assertKey(key: string, pointer: string[]) { ); } } + +const removeBrackets = (obj: any): any => { + if (!obj || typeof obj !== 'object') return obj; + + // Handle arrays + if (Array.isArray(obj)) { + return obj.map((item) => removeBrackets(item)); + } + + return Object.entries(obj).reduce((acc, [key, value]) => { + // Remove surrounding brackets if they exist + const newKey = key.replace(/^\[(.*)\]$/, '$1'); + + // Handle arrays in values + if (Array.isArray(value)) { + acc[newKey] = value.map((item) => removeBrackets(item)); + } else if (typeof value === 'object' && value !== null) { + // Recursively removeBrackets nested objects + acc[newKey] = removeBrackets(value); + } else { + // Handle primitive values + acc[newKey] = value; + } + + return acc; + }, {} as any); +}; + +export const parseQuery = (queryString: string) => { + return removeBrackets(qs.parse(queryString)); +};