File tree Expand file tree Collapse file tree 1 file changed +7
-11
lines changed
Expand file tree Collapse file tree 1 file changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -392,12 +392,10 @@ function big5decoder(loose) {
392392 // Input is assumed to be typechecked already
393393 let lead = 0
394394 let big5
395- const pushback = [ ]
396395 return ( arr , stream = false ) => {
397396 const onErr = loose
398397 ? ( ) => '\uFFFD'
399398 : ( ) => {
400- pushback . length = 0 // the queue is cleared on returning an error
401399 // Lead is always already cleared before throwing
402400 throw new TypeError ( E_STRICT )
403401 }
@@ -410,8 +408,8 @@ function big5decoder(loose) {
410408 }
411409
412410 if ( ! big5 ) big5 = getTable ( 'big5' )
413- for ( let i = res . length ; i < length || pushback . length > 0 ; ) {
414- const b = pushback . length > 0 ? pushback . pop ( ) : arr [ i ++ ]
411+ for ( let i = res . length ; i < length ; i ++ ) {
412+ const b = arr [ i ]
415413 if ( lead ) {
416414 let cp
417415 if ( ( b >= 0x40 && b <= 0x7e ) || ( b >= 0xa1 && b !== 0xff ) ) {
@@ -423,7 +421,8 @@ function big5decoder(loose) {
423421 res += cp // strings
424422 } else {
425423 res += onErr ( )
426- if ( b < 128 ) pushback . push ( b )
424+ // same as pushing it back: lead is cleared, pushed back can't contain more than 1 byte
425+ if ( b < 128 ) res += String . fromCharCode ( b )
427426 }
428427 } else if ( b < 128 ) {
429428 res += String . fromCharCode ( b )
@@ -434,13 +433,10 @@ function big5decoder(loose) {
434433 }
435434 }
436435
437- if ( ! stream ) {
436+ if ( ! stream && lead ) {
438437 // Destroy decoder state
439- pushback . length = 0
440- if ( lead ) {
441- lead = 0
442- res += onErr ( )
443- }
438+ lead = 0
439+ res += onErr ( )
444440 }
445441
446442 return res
You can’t perform that action at this time.
0 commit comments