express
express copied to clipboard
add encoding to UTF-8 for res.json and res.jsonp
Based on the IETF RFC4627:
JSON text SHALL be encoded in Unicode. The default encoding is UTF-8
I updated some references for the res.json and res.jsonp. The thing is that the tests are passing w/o additional changes so I am wondering if I am missing something here.
Pretty sure this is something we would need to land in v5 right? I think explicit is sometimes better, but I would need to do some research on how different clients behave to know for sure. Have you looked beyond the spec to see if there is some reason this might have been left off despite being pretty clearly specified?
It was left off bc code elsewhere adds it already. If you look at the http response qithout this change the charset is there in published versions.
The reason it is added elsewhere is bc nothing in that function is writing out utf-8 bytes to the response, so it leaves the part of the code that does that responsible to setting rhe charset of the bytes it actually wrote on the wire.
Ah, that makes sense. Thanks for the clarification! Do you have a link to where it does happen, just making sure I understand this going forward.