Skip to content

Commit

Permalink
core/http: protect param objects from applying params whos val is und…
Browse files Browse the repository at this point in the history
…efined
  • Loading branch information
b1lly committed Jun 21, 2019
1 parent b90b186 commit c4cab62
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/core/http/apirequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,24 @@ export default class ApiRequest {
'v': this._version,
'api_key': this._apiKey
};

const urlParams = new URL(window.location.toString()).searchParams;

if (urlParams.has('beta')) {
baseParams['beta'] = urlParams.get('beta');
}

// Remove any paramaters whos value is `undefined`.
//
// NOTE(billy) Probably better to be explicit about how to handle this at the request building level,
// but I can't see any cases where we'd ever want to send 'undefined' as a value to the server.
// So it's probably fine to 'clean' the params object here
Object.keys(params).forEach(key => {
if (params[key] === undefined) {
delete params[key];
}
});

return Object.assign(baseParams, params || {});
}
}

0 comments on commit c4cab62

Please sign in to comment.