Closed aimee-gm closed 7 months ago
Hi! Thanks for reporting this. This really belongs in the MSW repo.
Would the correct length of that unicode character be 3? Looks like we'd have to get the byte length instead of the string length in MSW as a bugfix. Waiting for you to confirm the expected length.
Reported here: https://github.com/mswjs/msw/issues/2045
Background
Last week,
msw@2.2.0
was released. As part of this, https://github.com/mswjs/msw/pull/1996 (feat: automatically set "Content-Length" on text/json responses) was included.This now adds a
Content-Length
header to all responses, calculated frombody.length.toString()
The issue
On upgradeing to msw@2.2.1, I've been having an issue where the generated content-length is incorrect and my response has been truncated when using special characters.
I believe this affects all responses with unicode characters and breaks this package with the latest version of msw when suing unicode characters.
Reproduction
Use
msw@^2.2.0
Modify the example to the following:
Output:
The
Content-Length
was incorrectly calculated as 2 short.