colyseus / uWebSockets-express

Express API compatibility layer for uWebSockets.js
https://npmjs.com/package/uwebsockets-express
MIT License
56 stars 13 forks source link

Fix JSON body with multibyte strings. #34

Closed hunkydoryrepair closed 7 months ago

hunkydoryrepair commented 7 months ago

Added new test "multibyte character body" which would fail as it was.

_rawbody gets send to the data handler of the express raw-data handler, which validates the data.length is equal to the content-length header. Converting the data to a string changes the length from bytes to characters, so this failed every time with multibyte characters.

Set _rawBody to retain the length in bytes (it remains a buffer), and it converted to string only when body getter is called.

_bodydata seems to only be used if something externally sets it via the body setter, so I did not want to change that.

(also fixed axios version to 1.4 so the userAgent test would pass).

hunkydoryrepair commented 7 months ago

I'm not sure what Node 20 is failing...looks like Axios is completely broken and I doubt related to my changes

endel commented 7 months ago

Thank you for the PR @hunkydoryrepair 🙏 Just released new version with your fix

Strange that Node v20 is failing indeed - I'm afraid it's related to uWebSockets.js binaries for that version. I'll investigate this a bit later as the examples under examples folder all seem to be working fine