Skip to content

Commit d9f36f8

Browse files
committed
fix: ignoreBOM support in TextDecoder polyfill
1 parent b6a9857 commit d9f36f8

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

bundler/modules/text-encoding-utf.cjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ function TextDecoder(encoding = UTF8, options = {}) {
6565
assertUTF8orUTF16LE(encoding)
6666

6767
const { fatal = false, ignoreBOM = false, stream = false } = options
68-
if (ignoreBOM !== false) throw new Error('option "ignoreBOM" is not supported')
6968
if (stream !== false) throw new Error('option "stream" is not supported')
7069

7170
// see: https://github.com/inexorabletash/text-encoding/blob/master/lib/encoding.js#L1049
@@ -91,7 +90,7 @@ TextDecoder.prototype.decode = function (buf) {
9190
}
9291
}
9392

94-
return res
93+
return !this.ignoreBOM && res.codePointAt(0) === 0xfeff ? res.slice(1) : res
9594
}
9695

9796
module.exports = { TextEncoder, TextDecoder }

0 commit comments

Comments
 (0)