Skip to content

Commit

Permalink
accidentally removed original fix haha
Browse files Browse the repository at this point in the history
  • Loading branch information
tintinthong committed Nov 4, 2024
1 parent 2611f1a commit b6e0fe1
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/runtime-common/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};

0 comments on commit b6e0fe1

Please sign in to comment.