File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -100,10 +100,11 @@ export class TextDecoder {
100100 }
101101 }
102102
103+ let seenBOM = false
103104 if ( this . #canBOM) {
104105 const bom = this . #findBom( prefix ?? u )
105106 if ( bom ) {
106- if ( stream ) this . #canBOM = false
107+ seenBOM = true
107108 if ( prefix ) {
108109 prefix = prefix . subarray ( bom )
109110 } else {
@@ -117,7 +118,8 @@ export class TextDecoder {
117118 if ( ! this . #decode) this . #decode = unicodeDecoder ( this . encoding , ! this . fatal )
118119 try {
119120 const res = ( prefix ? this . #decode( prefix ) : '' ) + this . #decode( u ) + suffix
120- if ( res . length > 0 && stream ) this . #canBOM = false
121+ // "BOM seen" is set on the current decode call only if it did not error, in "serialize I/O queue" after decoding
122+ if ( stream && ( seenBOM || res . length > 0 ) ) this . #canBOM = false
121123 return res
122124 } catch ( err ) {
123125 this . #chunk = null // reset unfinished chunk on errors
You can’t perform that action at this time.
0 commit comments