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

characters are corrupted in request payload when default charset encoding is not UTF-8 #379

Open
apptaro opened this issue Jun 8, 2022 · 0 comments

Comments

@apptaro
Copy link
Contributor

apptaro commented Jun 8, 2022

When the default charset encoding (file.encoding) is not UTF-8, twitterClient.postTweet("あいうえお") results in a tweet whose characters are corrupted.

This is because twittered uses OAuthRequest.setPayload(String), and ScribeJava uses String.getBytes() to obtain the byte array data of the request payload. To fix this issue, twittered should use OAuthRequest.setPayload(byte[]) and pass the result of String.getBytes(StandardCharset.UTF_8) at the code below:

https://github.com/redouane59/twittered/blob/develop/src/main/java/io/github/redouane59/twitter/helpers/AbstractRequestHelper.java#L76

Note: Json should always be encoded in UTF-8 as defined by RFC 8259.


Just for reference, below is the related code sections in ScribeJava:

com.github.scribejava.core.model.OAuthRequest.setPayload(String payload)
https://github.com/scribejava/scribejava/blob/master/scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequest.java#L180

com.github.scribejava.core.oauth.OAuthService.execute(OAuthRequest request)
https://github.com/scribejava/scribejava/blob/master/scribejava-core/src/main/java/com/github/scribejava/core/oauth/OAuthService.java#L108

com.github.scribejava.core.httpclient.jdk.JDKHttpClient.BodyType.setBody(String body)
https://github.com/scribejava/scribejava/blob/master/scribejava-core/src/main/java/com/github/scribejava/core/httpclient/jdk/JDKHttpClient.java#L164

apptaro added a commit to apptaro/twittered that referenced this issue Jun 8, 2022
redouane59 pushed a commit that referenced this issue Jun 9, 2022
* Fix for issue #379

* Fix for build error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant