Comments (3)
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 usingnew TextEncoder().encode(str).length
would be better to calculateContent-Length
. Thank you
![image](https://private-user-images.githubusercontent.com/10962668/306166235-e572955f-9eb6-4f18-840b-8730e87d89f5.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTE2NTM1OTUsIm5iZiI6MTcxMTY1MzI5NSwicGF0aCI6Ii8xMDk2MjY2OC8zMDYxNjYyMzUtZTU3Mjk1NWYtOWViNi00ZjE4LTg0MGItODczMGU4N2Q4OWY1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDAzMjglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwMzI4VDE5MTQ1NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWMyNDViNmIwZGEwMDgzMTU5ZWVkYmFhMzNkYzlkZjk5NWIyNWQ1YzQ0MjBlY2IyZDI5ZWQ3MjY2OTQwMGRmMmMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.GV_2vkV1iVsL78oBvoueTg8J7DX_MmbCSoOSBMWAfyg)
from msw.
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:
new TextEncoder().encode(text).byteLength
new Blob([text]).size
Pull requests are welcome! I'd start with a failing test for special characters right here:
msw/src/core/HttpResponse.test.ts
Line 16 in 23fc364
from msw.
Released: v2.2.2 ๐
This has been released in v2.2.2!
- ๐ Release notes
- ๐ฆ npm package
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)
- Failing to intercept an Axios request: Node 20.11 + Vitest 1.3.1 + MSW 2.2.1
- v2.2.2 does not intercept request in browser mode (CORS error) but v1.3.1 does HOT 3
- Infering the `boundary` callback arguments HOT 10
- support custom fetch option HOT 7
- support selecting interceptors HOT 1
- Set-Cookie responses containing commas are not handled correctly HOT 1
- HttpResponse.json() throwing TypeError: Right-hand side of 'instanceof' is not an object. HOT 1
- Request with FormData body makes Jest hang forever HOT 6
- TypeError: Right-hand side of 'instanceof' is not an object HOT 4
- Cannot read properties of undefined (reading 'url') HOT 5
- Mocked data getting empty string HOT 8
- "InvalidStateError: The object is in invalid state" when mocking rest api
- Unable to use msw/node for testing solid-js due to `resolve.conditions` set to `browser` HOT 5
- drop CommonJS support HOT 2
- quiet: true should supress RESPONSE LISTENER logs HOT 4
- Narrowing the response body type in `HttpResponse.json` HOT 16
- Error: No known conditions for "./browser" specifier in "msw" package HOT 5
- "Cannot read properties of undefined (reading 'get')" when using generators/async generators as resolvers HOT 2
- `TypeError: crypto.randomUUID is not a function` with msw 2.2.12 HOT 3
- When running Cypress tests in Electron, MSW activation occurs after test completion, causing tests to fail
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from msw.