mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
perf: optimize Buffer.from("base64") for forgiving-base64 conforming input (#24346)
This commit is contained in:
parent
6da87450ed
commit
2549e5154c
1 changed files with 7 additions and 3 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue