From 37705036582bd7aa06631c5b2395dc9811355ed3 Mon Sep 17 00:00:00 2001 From: shayaantx <5449086+shayaantx@users.noreply.github.com> Date: Sun, 22 May 2022 21:32:02 -0400 Subject: [PATCH] Use utf8 encoding when sending post requests to lidarr, radarr, sonarr (#77) --- src/main/java/com/botdarr/api/lidarr/LidarrApi.java | 3 ++- src/main/java/com/botdarr/api/radarr/RadarrApi.java | 2 +- src/main/java/com/botdarr/api/sonarr/SonarrApi.java | 5 ++++- src/main/resources/version.txt | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/botdarr/api/lidarr/LidarrApi.java b/src/main/java/com/botdarr/api/lidarr/LidarrApi.java index dad814a..6ac2008 100644 --- a/src/main/java/com/botdarr/api/lidarr/LidarrApi.java +++ b/src/main/java/com/botdarr/api/lidarr/LidarrApi.java @@ -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; @@ -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); diff --git a/src/main/java/com/botdarr/api/radarr/RadarrApi.java b/src/main/java/com/botdarr/api/radarr/RadarrApi.java index 4fd1fb9..7d42529 100644 --- a/src/main/java/com/botdarr/api/radarr/RadarrApi.java +++ b/src/main/java/com/botdarr/api/radarr/RadarrApi.java @@ -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); diff --git a/src/main/java/com/botdarr/api/sonarr/SonarrApi.java b/src/main/java/com/botdarr/api/sonarr/SonarrApi.java index 70a9d93..be2823b 100644 --- a/src/main/java/com/botdarr/api/sonarr/SonarrApi.java +++ b/src/main/java/com/botdarr/api/sonarr/SonarrApi.java @@ -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 { @@ -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(); diff --git a/src/main/resources/version.txt b/src/main/resources/version.txt index 86f2a61..229793a 100644 --- a/src/main/resources/version.txt +++ b/src/main/resources/version.txt @@ -1 +1 @@ -5.3.4 \ No newline at end of file +5.3.5 \ No newline at end of file