Skip to content

UTF-8 decoding broken on browsers without blob support #1480

Description

@Murreey

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions