Code Monkey home page Code Monkey logo

Comments (3)

ZeroCho avatar ZeroCho commented on June 25, 2024

I left a comment in #1658 but as this is the same problem with mine, I'll copy it here.

I have an issue with 2.2.0+ version of MSW, when I put CJK(Chinese, Japanese, Korean character) in MSW response.
Until [email protected], it was fine. I checked out what was changed in 2.2.0, and I found this commit could be the problem.

For example, the length of string '์กฐํ˜„์˜' (which is Korean) is 9 bytes in network, whereas 'abc' is 3 bytes. But both are 3 lengths in JavaScript. I think current implementation which calculate length by just string.length can be problem.
I think using new TextEncoder().encode(str).length would be better to calculate Content-Length. Thank you

image

from msw.

kettanaito avatar kettanaito commented on June 25, 2024

Root cause

Right now, we are relying on the string length to determine the value of the automatic Content-Length response header.

Instead, we should convert the string to buffer and measure its byte length. There are a couple of ways to do that:

  1. new TextEncoder().encode(text).byteLength
  2. new Blob([text]).size

Pull requests are welcome! I'd start with a failing test for special characters right here:

describe('HttpResponse.text()', () => {

from msw.

kettanaito avatar kettanaito commented on June 25, 2024

Released: v2.2.2 ๐ŸŽ‰

This has been released in v2.2.2!

Make sure to always update to the latest version (npm i msw@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

from msw.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.