From b0e6f33b872f60e3ff9b58720daf8182433fb1d9 Mon Sep 17 00:00:00 2001 From: Louis Vallat Date: Tue, 6 Aug 2019 11:22:38 +0200 Subject: [PATCH] fixed errors on parsing text due to JSON legacy compatibilities process in the REDDIT JSON API. from https://www.reddit.com/dev/api : "response body encoding For legacy reasons, all JSON response bodies currently have <, >, and & replaced with <, >, and &, respectively. If you wish to opt out of this behaviour, add a raw_json=1 parameter to your request." --- reddit_reposter_bot/build/built-jar.properties | 2 +- .../src/RedditReposterBot/ConfigFileReader.java | 7 +++---- .../src/RedditReposterBot/Hypervisor.java | 11 +++++------ .../src/RedditReposterBot/RedditReposterBot.java | 2 +- .../redditHandler/RedditExtractor.java | 14 +++++++++++--- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/reddit_reposter_bot/build/built-jar.properties b/reddit_reposter_bot/build/built-jar.properties index 95f95bb..7d2a3b6 100644 --- a/reddit_reposter_bot/build/built-jar.properties +++ b/reddit_reposter_bot/build/built-jar.properties @@ -1,4 +1,4 @@ -#Mon, 15 Jul 2019 21:54:15 +0200 +#Tue, 06 Aug 2019 11:12:49 +0200 C\:\\Users\\louis\\Documents\\GitHub\\twitter_techsupportgore_bot\\reddit_reposter_bot= diff --git a/reddit_reposter_bot/src/RedditReposterBot/ConfigFileReader.java b/reddit_reposter_bot/src/RedditReposterBot/ConfigFileReader.java index 00769c7..eccd202 100644 --- a/reddit_reposter_bot/src/RedditReposterBot/ConfigFileReader.java +++ b/reddit_reposter_bot/src/RedditReposterBot/ConfigFileReader.java @@ -67,8 +67,8 @@ public final class ConfigFileReader { /** * Read the config file. * - * @throws TwitterTechSupportGoreBot.exceptions.NotSufficientRights - * @throws TwitterTechSupportGoreBot.exceptions.NoSuchFile + * @throws RedditReposterBot.exceptions.NoSuchFile + * @throws RedditReposterBot.exceptions.NotSufficientRights */ public void readConfigFile() throws NoSuchFile, NotSufficientRights { if (!new File(CONFIGFILE).exists()) { @@ -93,8 +93,7 @@ public final class ConfigFileReader { * * @param id the property id. * @return the properties. - * - * @throws TwitterTechSupportGoreBot.exceptions.NoSuchProperty + * @throws RedditReposterBot.exceptions.NoSuchProperty */ public String getProperties(String id) throws NoSuchProperty { if (!this.prop.containsKey(id)) { diff --git a/reddit_reposter_bot/src/RedditReposterBot/Hypervisor.java b/reddit_reposter_bot/src/RedditReposterBot/Hypervisor.java index bedacc8..49484bf 100644 --- a/reddit_reposter_bot/src/RedditReposterBot/Hypervisor.java +++ b/reddit_reposter_bot/src/RedditReposterBot/Hypervisor.java @@ -129,12 +129,12 @@ public class Hypervisor { * @return the instance. * * @throws java.lang.ClassNotFoundException - * @throws TwitterTechSupportGoreBot.exceptions.NotSufficientRights + * @throws RedditReposterBot.exceptions.NotSufficientRights * @throws java.sql.SQLException * @throws java.io.IOException - * @throws TwitterTechSupportGoreBot.exceptions.NoSuchFile - * @throws TwitterTechSupportGoreBot.exceptions.NoSuchProperty - * @throws TwitterTechSupportGoreBot.exceptions.NoSuchOrder + * @throws RedditReposterBot.exceptions.NoSuchFile + * @throws RedditReposterBot.exceptions.NoSuchProperty + * @throws RedditReposterBot.exceptions.NoSuchOrder */ public static Hypervisor getSingleton() throws ClassNotFoundException, NotSufficientRights, @@ -399,8 +399,7 @@ public class Hypervisor { * Set working directory. * * @param tempDir the path to the working directory. - * - * @throws TwitterTechSupportGoreBot.exceptions.NotSufficientRights + * @throws RedditReposterBot.exceptions.NotSufficientRights */ public void setWorkDir(String tempDir) throws NotSufficientRights { this.workingDirectory = tempDir; diff --git a/reddit_reposter_bot/src/RedditReposterBot/RedditReposterBot.java b/reddit_reposter_bot/src/RedditReposterBot/RedditReposterBot.java index d148b13..c6bbbc1 100644 --- a/reddit_reposter_bot/src/RedditReposterBot/RedditReposterBot.java +++ b/reddit_reposter_bot/src/RedditReposterBot/RedditReposterBot.java @@ -34,7 +34,7 @@ public class RedditReposterBot { /** * Version of the application. */ - private static final String VERSION = "0.9.1"; + private static final String VERSION = "1.0.1"; /** * Launch the Hypervisor. diff --git a/reddit_reposter_bot/src/RedditReposterBot/redditHandler/RedditExtractor.java b/reddit_reposter_bot/src/RedditReposterBot/redditHandler/RedditExtractor.java index 8bd765b..5d7a7f8 100644 --- a/reddit_reposter_bot/src/RedditReposterBot/redditHandler/RedditExtractor.java +++ b/reddit_reposter_bot/src/RedditReposterBot/redditHandler/RedditExtractor.java @@ -157,9 +157,17 @@ public final class RedditExtractor { String title = childData.get("title") != null ? childData.get("title").toString() : this.sub.getName(); - title = title.replace("\"", "").replace("\\", "\""); + title = title + .replace("\"", "") + .replace("\\", "\"") + .replace("<", "<") + .replace(">", ">") + .replace("&", "&"); String author = childData.get("author") != null - ? childData.get("author").toString() : "anonymous"; + ? childData.get("author").toString() + .replace("<", "<") + .replace(">", ">") + .replace("&", "&") : "anonymous"; author = author.replace("\"", ""); boolean quarantine = childData.get("quarantine") .getAsBoolean(); @@ -178,7 +186,7 @@ public final class RedditExtractor { .get(0).toString()).getAsJsonObject(); JsonObject urlSrc = new JsonParser().parse(source .get("source").toString()).getAsJsonObject(); - url = urlSrc.get("url").toString().replace("amp;", "") + url = urlSrc.get("url").toString().replace("&", "&") .replace("\"", ""); } catch (NullPointerException n) { url = childData.get("url").getAsString();