Skip to content

Commit

Permalink
fix: apply custom encoder to base64 parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
sherwinski authored and sherwinski committed Jan 13, 2023
1 parent 9b557e2 commit 3ca78e1
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/index.js
Expand Up @@ -105,7 +105,8 @@ export default class ImgixClient {
_buildParams(params = {}, options = {}) {
// If a custom encoder is present, use it
// Otherwise just use the encodeURIComponent
const encode = options.encoder || encodeURIComponent
const useCustomEncoder = !!options.encoder;
const customEncoder = options.encoder;

const queryParams = [
// Set the libraryParam if applicable.
Expand All @@ -118,11 +119,11 @@ export default class ImgixClient {
if (value == null) {
return prev;
}
const encodedKey = encode(key);
const encodedKey = useCustomEncoder ? customEncoder(key) : encodeURIComponent(key);
const encodedValue =
key.substr(-2) === '64'
? Base64.encodeURI(value)
: encode(value);
? useCustomEncoder ? customEncoder(value) : Base64.encodeURI(value)
: useCustomEncoder ? customEncoder(value) : encodeURIComponent(value);
prev.push(`${encodedKey}=${encodedValue}`);

return prev;
Expand Down

0 comments on commit 3ca78e1

Please sign in to comment.