From 74294bad557e7079dac30b45853cba1271046d6f Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Mon, 7 Jul 2014 21:01:37 +0200 Subject: [PATCH] Remove leading and trailing whitespace in URLChecker. fixes #461 --- src/de/danoeh/antennapod/util/URLChecker.java | 4 ++++ .../de/test/antennapod/util/URLCheckerTest.java | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/de/danoeh/antennapod/util/URLChecker.java b/src/de/danoeh/antennapod/util/URLChecker.java index af0226ce0..9997daaf7 100644 --- a/src/de/danoeh/antennapod/util/URLChecker.java +++ b/src/de/danoeh/antennapod/util/URLChecker.java @@ -1,6 +1,9 @@ package de.danoeh.antennapod.util; import android.util.Log; + +import org.apache.commons.lang3.StringUtils; + import de.danoeh.antennapod.BuildConfig; /** @@ -27,6 +30,7 @@ public final class URLChecker { */ public static String prepareURL(String url) { StringBuilder builder = new StringBuilder(); + url = StringUtils.trim(url); if (url.startsWith("feed://")) { if (BuildConfig.DEBUG) Log.d(TAG, "Replacing feed:// with http://"); url = url.replaceFirst("feed://", "http://"); diff --git a/src/instrumentationTest/de/test/antennapod/util/URLCheckerTest.java b/src/instrumentationTest/de/test/antennapod/util/URLCheckerTest.java index 18e8bf007..91e5d966f 100644 --- a/src/instrumentationTest/de/test/antennapod/util/URLCheckerTest.java +++ b/src/instrumentationTest/de/test/antennapod/util/URLCheckerTest.java @@ -43,4 +43,16 @@ public class URLCheckerTest extends AndroidTestCase { final String out = URLChecker.prepareURL(in); assertEquals("http://example.com", out); } + + public void testWhiteSpaceUrlShouldNotAppend() { + final String in = "\n http://example.com \t"; + final String out = URLChecker.prepareURL(in); + assertEquals("http://example.com", out); + } + + public void testWhiteSpaceShouldAppend() { + final String in = "\n example.com \t"; + final String out = URLChecker.prepareURL(in); + assertEquals("http://example.com", out); + } }