Hi, I am not sure if this is a bug or was a planned changed but after upgrading msw to the latest version, part of my tests started to fail. I fount this commit that changes the condition to parse the body.
Now when we have the following header:
Content-Type: application/json; charset=UTF-8
The body is not parsed.
msw: 0.22.0nodejs: 12.19.0npm: 6.14.8Steps to reproduce the behavior:
Content-Type: application/json; charset=UTF-8req.body inside the request handler will be a stringWhen the content-type header is application/json, the body is automatically parsed.
Hi, @otaciliolacerda. Thanks for reporting this.
That's a great catch, I believe that commit overlooks the charset as a part of the Content-Type request header. Reverting the logic to use .includes() should resolve the issue.
Would you be interested in shipping a pull request?
Yes, I will take a look on this. Thanks for the super fast reply.
.includes may be susceptible to errors if the Content-Type header includes an arbitrary content type, or a content type that includes the phrase "json" but does not represent an actual JSON content type. However, I still suggest we revert to .includes and address that only when such issue arises.