diff --git a/packages/core/src/infrastructure/Utils.ts b/packages/core/src/infrastructure/Utils.ts index e2e9a8335..678d09cf5 100644 --- a/packages/core/src/infrastructure/Utils.ts +++ b/packages/core/src/infrastructure/Utils.ts @@ -74,13 +74,13 @@ export function reformatObjectOptions( obj: Record, prefixKey: string, decamelizeValues = false, -) { +): Record { const formatted = decamelizeValues ? decamelizeKeys(obj) : obj; return QS.stringify({ [prefixKey]: formatted }, { encode: false }) .split('&') .reduce((acc: Record, cur: string) => { - const [key, val] = cur.split('='); + const [key, val] = cur.split(/=(.*)/); acc[key] = val; diff --git a/packages/core/test/unit/infrastructure/Utils.ts b/packages/core/test/unit/infrastructure/Utils.ts index ef5228c33..124afff4d 100644 --- a/packages/core/test/unit/infrastructure/Utils.ts +++ b/packages/core/test/unit/infrastructure/Utils.ts @@ -1,4 +1,4 @@ -import { appendFormFromObject, endpoint } from '../../../src/infrastructure'; +import { appendFormFromObject, endpoint, reformatObjectOptions } from '../../../src/infrastructure'; describe('appendFormFromObject', () => { it('should convert object key/values to formdata instance', () => { @@ -35,3 +35,29 @@ describe('endpoint', () => { expect(url).toBe('/projects/1'); }); }); + +describe('reformatObjectOptions', () => { + it('should convert simple nested object to be query parameter friendly', () => { + const data = { + a: { + b: 'test', + }, + }; + + const formatted = reformatObjectOptions(data, 'test'); + + expect(formatted).toMatchObject({ 'test[a][b]': 'test' }); + }); + + it('should convert nested object with "=" characters in the value', () => { + const data = { + a: { + b: '=5', + }, + }; + + const formatted = reformatObjectOptions(data, 'test'); + + expect(formatted).toMatchObject({ 'test[a][b]': '=5' }); + }); +});