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

Recover gracefully instead of throwing IllegalCharsetNameException #2677

Closed
Biswangluo opened this issue Jun 29, 2016 · 3 comments
Closed

Recover gracefully instead of throwing IllegalCharsetNameException #2677

Biswangluo opened this issue Jun 29, 2016 · 3 comments
Labels
enhancement Feature not a bug
Milestone

Comments

@Biswangluo
Copy link

Wrong data from server
#1.

`

<title>系统发生错误</title> <style type="text/css">` #2

557 4920-5047/arkui.live W/System.err: java.nio.charset.IllegalCharsetNameException: 'utf-8'
06-29 12:47:49.557 4920-5047/arkui.live W/System.err: at java.nio.charset.Charset.checkCharsetName(Charset.java:197)
06-29 12:47:49.557 4920-5047/arkui.live W/System.err: at java.nio.charset.Charset.forName(Charset.java:295)
06-29 12:47:49.557 4920-5047/arkui.live W/System.err: at okhttp3.MediaType.charset(MediaType.java:103)
06-29 12:47:49.557 4920-5047/arkui.live W/System.err: at okhttp3.ResponseBody.charset(ResponseBody.java:159)
06-29 12:47:49.557 4920-5047/arkui.live W/System.err: at okhttp3.ResponseBody.string(ResponseBody.java:154)
06-29 12:47:49.557 4920-5047/arkui.live W/System.err: at arkui.live.dao.LoadDataUtil$1.onResponse(LoadDataUtil.java:82)
06-29 12:47:49.557 4920-5047/arkui.live W/System.err: at okhttp3.RealCall$AsyncCall.execute(RealCall.java:133)
06-29 12:47:49.557 4920-5047/arkui.live W/System.err: at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
06-29 12:47:49.557 4920-5047/arkui.live W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
06-29 12:47:49.557 4920-5047/arkui.live W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
06-29 12:47:49.557 4920-5047/arkui.live W/System.err: at java.lang.Thread.run(Thread.java:818)

@swankjesse
Copy link
Collaborator

It looks like your server is returning a header like this:

Content-Type: text/html; charset='utf-8'

Unfortunately according to RFC 822, use of single quotes isn’t valid in a media type parameter. Instead the content type should be this:

Content-Type: text/html; charset="utf-8"

Please ask your server team to fix their broken response headers.
https://tools.ietf.org/html/rfc822

I’m unsure what action OkHttp should take here. Probably our best bet is to see how web browsers like Chrome and Firefox handle invalid charsets and do likewise.

@swankjesse swankjesse changed the title [BUG] java.nio.charset.IllegalCharsetNameException: 'utf-8' Recover gracefully instead of throwing IllegalCharsetNameException Jul 1, 2016
@swankjesse swankjesse added the enhancement Feature not a bug label Jul 1, 2016
@swankjesse swankjesse added this to the 3.5 milestone Jul 1, 2016
@Biswangluo
Copy link
Author

thank you

@swankjesse
Copy link
Collaborator

swankjesse commented Jul 11, 2016

Chrome treats single quotes interchangeably with double quotes. Safari and Firefox ignore the malformed charset parameter and detect it from the content.

swankjesse pushed a commit that referenced this issue Jul 11, 2016
It's what Chrome does. Firefox and Safari ignore it. I'd love to ignore
it, but in our API that really just means the caller needs to handle an
InvalidCharsetNameException and nobody is expecting that.

Closes: #2677
swankjesse pushed a commit that referenced this issue Jul 11, 2016
It's what Chrome does. Firefox and Safari ignore it. I'd love to ignore
it, but in our API that really just means the caller needs to handle an
InvalidCharsetNameException and nobody is expecting that.

Closes: #2677
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature not a bug
Projects
None yet
Development

No branches or pull requests

2 participants