-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Encoding::UndefinedConversionError: "\xF0" from ASCII-8BIT to UTF-8 #786
Comments
Does setting LANG to |
LANG header doesn't help. |
Calling class API < Grape::API
post do
params[:body].force_encoding(Encoding::UTF_8)
{ body: params[:body] }.to_json
end
end Maybe it should be called on all Something like: before { params.each { |k, v| v.force_encoding(Encoding::UTF_8) if v.is_a?(String) } } |
I definitely don't think you should be doing |
I just read that you're saying you can't generate a content type. This has to be possible, somehow? |
Even when I force charset (I used Charles to do it) it doesn't use the right encoding:
Gives the same error. Isn't it what Rails' hidden input utf8 resolving? |
What's also weird is that only real UTF-8 strings are encoded as ASCII-8BIT before { params.each { |k, v| ap [k, v, v.encoding] if v.is_a?(String) } }
[
[0] "body",
[1] "\xF0\x9F\x98\x88",
[2] #<Encoding:ASCII-8BIT>
]
[
[0] "extra",
[1] "string",
[2] #<Encoding:UTF-8>
]
|
I think this is a legit bug. Maybe you can try to turn it into a spec? |
I had the same error when I post some Chinese characters. |
Ok I just had the same issue here.
|
have the same issue, anybody resolved this problem without doing the force_encoding hack? |
@chrisdebruin , try update your BTW, @sbounmy is right,
You can use I'll close this. |
@dm1try thnx works for me |
I get the following error when I post a file with extra body that contains UTF-8 chars, and trying to convert those fields to JSON:
Example app:
Run with
bundle exec rackup -p3000
Call with
curl -X POST --form "body=😈&file=@file.jpg" http://localhost:3000 --trace-ascii dump.txt
In this case the 😈 is an emoji (not sure it's visible here).
Since it's a multipart/form-data I can't set charset on the Content-Type as the request generates a random boundary. I'm not even sure it'd help.
Any suggestions?
The text was updated successfully, but these errors were encountered: