From 6cc01f9968e9e67e6819ae48daa604733c9a5efe Mon Sep 17 00:00:00 2001 From: lantzelot-swe Date: Thu, 14 Jan 2021 23:02:55 +0100 Subject: [PATCH] fix: validation of url --- src/main/java/se/lantz/scraper/C64comScraper.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/se/lantz/scraper/C64comScraper.java b/src/main/java/se/lantz/scraper/C64comScraper.java index 40612dd..c415c3d 100644 --- a/src/main/java/se/lantz/scraper/C64comScraper.java +++ b/src/main/java/se/lantz/scraper/C64comScraper.java @@ -68,7 +68,7 @@ public class C64comScraper implements Scraper public void connect(String url) throws IOException { this.c64comGameUrl = ""; - //c64.com gives no errors for invalid urls. Check if there is an title to make sure it's valid + //c64.com gives no errors for invalid urls. Check if there is an non-empty title to make sure it's valid Connection.Response result = Jsoup.connect(url).method(Connection.Method.GET).execute(); Document doc = result.parse(); //Fetch right frame @@ -76,12 +76,9 @@ public class C64comScraper implements Scraper //Fetch title Elements queryElements = mainFrameDocument.select(titleCssQuery); Element first = queryElements.first(); - if (first != null) - { - if (first.text().isEmpty()) - { - throw new IllegalArgumentException(); - } + if (first == null || first.text().isEmpty()) + { + throw new IllegalArgumentException(); } this.c64comGameUrl = url;