Skip to content

Commit

Permalink
fix: ensure undefined parameters not added to url
Browse files Browse the repository at this point in the history
This commit ensures that undefined parameters are not added to the
params object generated by _buildParams. This way, undefined params do
not then end up in the generated URL.

Co-authored-by: Frederick Fogerty <[email protected]>
  • Loading branch information
luqven and Frederick Fogerty committed Jun 15, 2021
1 parent 85d054c commit f7fc708
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,18 @@ export default class ImgixClient {
: []),

// Map over the key-value pairs in params while applying applicable encoding.
...Object.entries(params).map(([key, value]) => {
...Object.entries(params).reduce((prev, [key, value]) => {
if (value == null) {
return prev;
}
const encodedKey = encodeURIComponent(key);
const encodedValue =
key.substr(-2) === '64'
? Base64.encodeURI(value)
: encodeURIComponent(value);
return `${encodedKey}=${encodedValue}`;
}),
prev.push(`${encodedKey}=${encodedValue}`);
return prev;
}, []),
];

return `${queryParams.length > 0 ? '?' : ''}${queryParams.join('&')}`;
Expand Down

0 comments on commit f7fc708

Please sign in to comment.