Skip to content

Commit

Permalink
Use utf8 encoding when sending post requests to lidarr, radarr, sonarr (
Browse files Browse the repository at this point in the history
  • Loading branch information
shayaantx authored May 23, 2022
1 parent 300acd7 commit 3770503
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/botdarr/api/lidarr/LidarrApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -265,7 +266,7 @@ private CommandResponse addArtist(LidarrArtist lidarrArtist) {
//lidarr for some reason doesn't support raw unicode characters in json parsing (since they should be allowed), so we escape them here
mapper.getFactory().configure(JsonGenerator.Feature.ESCAPE_NON_ASCII, true);
String json = mapper.writeValueAsString(lidarrArtist);
post.setEntity(new StringEntity(json));
post.setEntity(new StringEntity(json, Charset.forName("UTF-8")));

if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Client request=" + post);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/botdarr/api/radarr/RadarrApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private CommandResponse addMovie(RadarrMovie radarrMovie) {

post.addHeader("content-type", "application/json");
String json = new Gson().toJson(radarrMovie, RadarrMovie.class);
post.setEntity(new StringEntity(json));
post.setEntity(new StringEntity(json, Charset.forName("UTF-8")));

if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Client request=" + post);
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/botdarr/api/sonarr/SonarrApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.*;

public class SonarrApi implements Api {
Expand Down Expand Up @@ -221,7 +222,9 @@ private CommandResponse addShow(SonarrShow sonarrShow) {
HttpPost post = new HttpPost(getApiUrl(SonarrUrls.SERIES_BASE));

post.addHeader("content-type", "application/x-www-form-urlencoded");
post.setEntity(new StringEntity(new GsonBuilder().addSerializationExclusionStrategy(excludeUnnecessaryFields).create().toJson(sonarrShow, SonarrShow.class)));
post.setEntity(
new StringEntity(
new GsonBuilder().addSerializationExclusionStrategy(excludeUnnecessaryFields).create().toJson(sonarrShow, SonarrShow.class), Charset.forName("UTF-8")));

try (CloseableHttpResponse response = client.execute(post)) {
int statusCode = response.getStatusLine().getStatusCode();
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.3.4
5.3.5

0 comments on commit 3770503

Please sign in to comment.