Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Do not use default parameter values for ie https://github.com/brix/crypto-js/pull/357 #374

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/enc-base64url.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
*
* var base64String = CryptoJS.enc.Base64url.stringify(wordArray);
*/
stringify: function (wordArray, urlSafe=true) {
stringify: function (wordArray, urlSafe) {
// Shortcuts
var words = wordArray.words;
var sigBytes = wordArray.sigBytes;
var map = urlSafe ? this._safe_map : this._map;
var map = urlSafe === undefined ? this._map : this._safe_map;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want

var map = urlSafe === undefined || urlSafe ? this._safe_map : this._map;

If urlSafe is undefined, you want this to default to true, so you want to use the _safe_map scenario. Or perhaps I'm missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use babel, you will find that the default value of the function parameter only needs to judge undefined.
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emmm...you are right, but i think maybe this way will be better?

var map = urlSafe ? this._safe_map : this._map;


// Clamp excess bits
wordArray.clamp();
Expand Down Expand Up @@ -73,10 +73,10 @@
*
* var wordArray = CryptoJS.enc.Base64url.parse(base64String);
*/
parse: function (base64Str, urlSafe=true) {
parse: function (base64Str, urlSafe) {
// Shortcuts
var base64StrLength = base64Str.length;
var map = urlSafe ? this._safe_map : this._map;
var map = urlSafe === undefined ? this._map : this._safe_map;
var reverseMap = this._reverseMap;

if (!reverseMap) {
Expand Down