Skip to content

Commit

Permalink
fix: undefined values in query params (#1187)
Browse files Browse the repository at this point in the history
Followup fix for d2ff8ec

Url params with undefined values need to be excluded from param serialization logic, since stream backend doesn't treat `undefined` same as param not being present.
  • Loading branch information
vishalnarkhede authored Oct 19, 2023
1 parent a4d18fd commit a325737
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ export function removeConnectionEventListeners(cb: (e: Event) => void) {
export const axiosParamsSerializer: AxiosRequestConfig['paramsSerializer'] = (params) => {
const newParams = [];
for (const k in params) {
// Stream backend doesn't treat "undefined" value same as value not being present.
// So, we need to skip the undefined values.
if (params[k] === undefined) continue;

if (Array.isArray(params[k]) || typeof params[k] === 'object') {
newParams.push(`${k}=${encodeURIComponent(JSON.stringify(params[k]))}`);
} else {
Expand Down
1 change: 1 addition & 0 deletions test/unit/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ describe('axiosParamsSerializer', () => {
a: 1,
b: 2,
c: null,
d: undefined,
},
output: 'a=1&b=2&c=null',
},
Expand Down

0 comments on commit a325737

Please sign in to comment.