UTF-8 decoding broken on browsers without blob support
Author: MurreeyCreated Apr 24, 2025Updated Apr 24, 2025
When using the polyfill on browsers that don't support blob but do support arrayBuffer, multibyte UTF-8 sequences don't get decoded properly.
Simple repro, you can mock the browser environment by forcefully setting support.blob false:
fetch('data:text/plain,èàì’')
.then(r => r.text())
.then(console.log) // logs "èà ìâ"Looks like this was introduced here in v3.6.15, it works alright previously. With that responseType always set, Body's text() runs the byte by byte buffer decode with String.fromCharCode(), which can't handle the multibyte sequences.
Would it make sense to only set xhr.responseType after the response headers arrive, so it can check the Content-Type as well as browser support?
Source: JakeChampion/fetch