-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include charset=utf-8
by default in application/json
endpoints.
#1669
Conversation
It looks like there are some CI failures |
Yep, this seems reasonable to do for responses that SvelteKit is automatically serializing. The test failures look like just some |
Sorry, it was quite late and my brain was foggy, I think I ran tests locally on the wrong directory. 🥶 I'll fix these after work, later today |
🦋 Changeset detectedLatest commit: c8cced1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@benmccann @Conduitry Fixed linting and the broken test. I also removed the value check for the response body in c8cced1, since upon further digging it looks like the tests don't actually encode/decode the strings as byte buffers like a real HTTP implementation would, so it wasn't really testing anything. |
Hey 👋 Let me know if you need me to make any additional changes or add more tests. I can add back the test for UTF-8 encoding/decoding if there's a sanctioned way to make the HTTP response binary during the tests (or I can also try to figure out a mechanism for this if not present) |
Hey there 👋
I was getting Mojibake when returning unicode data from my endpoints, so I checked the headers and noticed the
charset=utf-8
option was missing fromContent-Type
. This in turn was causing the response to incorrectly be interpreted as Windows-1252.This PR changes
src/runtime/server/endpoint.js
to include that by default fortypeof body === 'object'
.I couldn't find any tickets about this, believe this change is simple enough that it's okay for me to open a PR without filing a ticket first.
Before submitting the PR, please make sure you do the following
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpx changeset
and following the prompts