humanwhocodes/computer-science-in-javascript

Question about Base64Decode

AJLoveChina opened this issue · 1 comments

//ignore white space
text = text.replace(/\s/g,"");

//first check for any unexpected input
if(!(/^[a-z0-9\+\/\s]+\={0,2}$/i.test(text)) || text.length % 4 > 0){
    throw new Error("Not a base64-encoded string.");
} 
// Q : 
// if there is no space in the String text.
// Why not change RegExp to [a-z0-9\+\/] instead of [a-z0-9\+\/\s] ?

It's probably OK to do that.