Skip to content

Commit bae383f

Browse files
committed
minor perf improvement
1 parent 91f0f7b commit bae383f

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

base64.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ if (Uint8Array.fromBase64) {
8181
for (let i = 0; i < raw.length; i++) arr[i] = raw.charCodeAt(i)
8282
} else {
8383
// base64url is already checked to have no padding via a regex above
84-
if (!isBase64url) assert(!str.includes('=') || !/=[^=]/iu.test(str), 'Invalid padding')
84+
if (!isBase64url) {
85+
const at = str.indexOf('=')
86+
if (at >= 0) assert(!/[^=]/iu.test(str.slice(at)), 'Invalid padding')
87+
}
8588
arr = haveNativeBuffer ? Buffer.from(str, 'base64') : fromBase64js(str)
8689
}
8790

0 commit comments

Comments
 (0)