Skip to content

Commit

Permalink
perf: optimize Buffer.from("base64") for forgiving-base64 conforming …
Browse files Browse the repository at this point in the history
…input (denoland#24346)
  • Loading branch information
littledivy committed Jun 26, 2024
1 parent 6da8745 commit 2549e51
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions ext/node/polyfills/internal_binding/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ export function asciiToBytes(str: string) {
}

export function base64ToBytes(str: string) {
str = base64clean(str);
str = str.replaceAll("-", "+").replaceAll("_", "/");
return forgivingBase64Decode(str);
try {
return forgivingBase64Decode(str);
} catch {
str = base64clean(str);
str = str.replaceAll("-", "+").replaceAll("_", "/");
return forgivingBase64Decode(str);
}
}

const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
Expand Down

0 comments on commit 2549e51

Please sign in to comment.