Skip to content

Commit

Permalink
fix: encodeParam returned [object Object] for object types
Browse files Browse the repository at this point in the history
Now the object value is stringified JSON
  • Loading branch information
jkaster committed Apr 6, 2022
1 parent 5a183be commit 43c91ca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/sdk-rtl/src/transport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,8 @@ describe('Transport', () => {
expect(encodeParam('foo/bar')).toEqual('foo%2Fbar')
expect(encodeParam(true)).toEqual('true')
expect(encodeParam(2.3)).toEqual('2.3')
expect(encodeParam({ created_date: 'this year to second' })).toEqual(
'{"created_date":"this year to second"}'
)
})
})
4 changes: 3 additions & 1 deletion packages/sdk-rtl/src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,9 @@ export function encodeParam(value: any) {
if (value instanceof Date) {
value = value.toISOString()
}
let encoded = value.toString()
// check for object type to prevent "[object Object]" as the value.toString()
let encoded =
typeof value === 'object' ? JSON.stringify(value) : value.toString()

// decodeURIComponent throws URIError if there is a % character
// without it being part of an encoded
Expand Down

0 comments on commit 43c91ca

Please sign in to comment.