Skip to content
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

readBody() does not take into account application/x-www-form-urlencoded; charset=utf-8 #437

Closed
efraimbart opened this issue Jul 11, 2023 · 2 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@efraimbart
Copy link

efraimbart commented Jul 11, 2023

If charset=utf-8 is added to the content type readBody() will attempt to parse the body as json and fail. See

h3/src/utils/body.ts

Lines 107 to 115 in d11f817

if (contentType === "application/json") {
parsed = _parseJSON(body, options.strict ?? true) as T;
} else if (contentType === "application/x-www-form-urlencoded") {
parsed = _parseURLEncodedBody(body!) as T;
} else if (contentType.startsWith("text/")) {
parsed = body as T;
} else {
parsed = _parseJSON(body, options.strict ?? false) as T;
}
.

@Hebilicious
Copy link
Member

I think we should support charset in the content type header by either extracting it first or using string.contains

@Hebilicious Hebilicious added bug Something isn't working good first issue Good for newcomers labels Jul 13, 2023
@pi0 pi0 closed this as completed in 4af66eb Aug 1, 2023
@pi0
Copy link
Member

pi0 commented Aug 1, 2023

Thanks for reporting issue. It will be resolved in next release by (4af66eb). I have added an internal comment that in next iterations, we might actually use the charset to handle encoding.

@pi0 pi0 mentioned this issue Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants