11import { assertEmptyRest } from './assert.js'
22import { typedView } from './array.js'
3- import { assertU8 , E_STRING } from './fallback/_utils.js'
3+ import { assertU8 , fromUint8 , E_STRING } from './fallback/_utils.js'
44import { isHermes } from './fallback/platform.js'
55import { decodeLatin1 , encodeLatin1 } from './fallback/latin1.js'
66import * as js from './fallback/base64.js'
@@ -96,7 +96,7 @@ function fromBase64common(str, isBase64url, padding, format, rest) {
9696 throw new TypeError ( 'Invalid padding option' )
9797 }
9898
99- return typedView ( fromBase64impl ( str , isBase64url , padding ) , format )
99+ return fromBase64impl ( str , isBase64url , padding , format )
100100}
101101
102102// ASCII whitespace is U+0009 TAB, U+000A LF, U+000C FF, U+000D CR, or U+0020 SPACE
@@ -114,7 +114,7 @@ function noWhitespaceSeen(str, arr) {
114114let fromBase64impl
115115if ( Uint8Array . fromBase64 ) {
116116 // NOTICE: this is actually slower than our JS impl in older JavaScriptCore and (slightly) in SpiderMonkey, but faster on V8 and new JavaScriptCore
117- fromBase64impl = ( str , isBase64url , padding ) => {
117+ fromBase64impl = ( str , isBase64url , padding , format ) => {
118118 const alphabet = isBase64url ? 'base64url' : 'base64'
119119
120120 let arr
@@ -136,20 +136,20 @@ if (Uint8Array.fromBase64) {
136136 // We don't allow whitespace in input, but that can be rechecked based on output length
137137 // All other chars are checked natively
138138 if ( ! noWhitespaceSeen ( str , arr ) ) throw new SyntaxError ( E_CHAR )
139- return arr
139+ return fromUint8 ( arr , format )
140140 }
141141} else if ( haveNativeBuffer ) {
142- fromBase64impl = ( str , isBase64url , padding ) => {
142+ fromBase64impl = ( str , isBase64url , padding , format ) => {
143143 const arr = Buffer . from ( str , 'base64' )
144144 // Rechecking by re-encoding is cheaper than regexes on Node.js
145145 const got = isBase64url ? maybeUnpad ( str , padding === false ) : maybePad ( str , padding !== true )
146146 const valid = isBase64url ? arr . base64urlSlice ( 0 , arr . length ) : arr . base64Slice ( 0 , arr . length )
147147 if ( got !== valid ) throw new SyntaxError ( E_PADDING )
148- return arr // fully checked
148+ return typedView ( arr , format ) // fully checked
149149 }
150150} else if ( shouldUseAtob ) {
151151 // atob is faster than manual parsing on Hermes
152- fromBase64impl = ( str , isBase64url , padding ) => {
152+ fromBase64impl = ( str , isBase64url , padding , format ) => {
153153 let arr
154154 if ( isBase64url ) {
155155 if ( / [ \t \n \f \r + / ] / . test ( str ) ) throw new SyntaxError ( E_CHAR ) // atob verifies other invalid input
@@ -171,8 +171,9 @@ if (Uint8Array.fromBase64) {
171171 if ( expected !== end ) throw new SyntaxError ( E_LAST )
172172 }
173173
174- return arr
174+ return fromUint8 ( arr , format )
175175 }
176176} else {
177- fromBase64impl = ( str , isBase64url , padding ) => js . fromBase64 ( str , isBase64url ) // validated in js
177+ fromBase64impl = ( str , isBase64url , padding , format ) =>
178+ fromUint8 ( js . fromBase64 ( str , isBase64url ) , format ) // validated in js
178179}
0 commit comments