From d0960fad75d5f3f79055281e3d963f4a63582a10 Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Sun, 1 Jul 2018 19:25:32 -0400 Subject: [PATCH] Added better url sanitization for DeviantartRipper and some unit tests --- .../ripme/ripper/rippers/DeviantartRipper.java | 6 ++++-- .../tst/ripper/rippers/DeviantartRipperTest.java | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/DeviantartRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/DeviantartRipper.java index 279d82d1..cb3e7595 100644 --- a/src/main/java/com/rarchives/ripme/ripper/rippers/DeviantartRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/DeviantartRipper.java @@ -64,8 +64,10 @@ public class DeviantartRipper extends AbstractJSONRipper { public URL sanitizeURL(URL url) throws MalformedURLException { String u = url.toExternalForm(); - if (!u.endsWith("/gallery/")) { - if (!u.endsWith("/gallery")) { + if (!u.endsWith("/gallery/") && !u.endsWith("/gallery")) { + if (!u.endsWith("/")) { + u += "/gallery/"; + } else { u += "gallery/"; } } diff --git a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/DeviantartRipperTest.java b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/DeviantartRipperTest.java index 52b6bc59..6a1a054b 100644 --- a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/DeviantartRipperTest.java +++ b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/DeviantartRipperTest.java @@ -2,6 +2,8 @@ package com.rarchives.ripme.tst.ripper.rippers; import java.io.IOException; import java.net.URL; +import java.util.ArrayList; +import java.util.List; import com.rarchives.ripme.ripper.rippers.DeviantartRipper; import com.rarchives.ripme.utils.Http; @@ -32,4 +34,16 @@ public class DeviantartRipperTest extends RippersTest { assertEquals("airgee", ripper.getUsername(doc)); assertEquals("714589", ripper.getGalleryID(doc)); } + + public void testSanitizeURL() throws IOException { + List urls = new ArrayList(); + urls.add(new URL("https://www.deviantart.com/airgee/")); + urls.add(new URL("https://www.deviantart.com/airgee")); + urls.add(new URL("https://www.deviantart.com/airgee/gallery/")); + + for (URL url : urls) { + DeviantartRipper ripper = new DeviantartRipper(url); + assertEquals("https://www.deviantart.com/airgee/gallery/", ripper.sanitizeURL(url).toExternalForm()); + } + } }