Remove leading and trailing whitespace in URLChecker. fixes #461

This commit is contained in:
daniel oeh 2014-07-07 21:01:37 +02:00
parent f59623bb94
commit 74294bad55
2 changed files with 16 additions and 0 deletions

View File

@ -1,6 +1,9 @@
package de.danoeh.antennapod.util; package de.danoeh.antennapod.util;
import android.util.Log; import android.util.Log;
import org.apache.commons.lang3.StringUtils;
import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.BuildConfig;
/** /**
@ -27,6 +30,7 @@ public final class URLChecker {
*/ */
public static String prepareURL(String url) { public static String prepareURL(String url) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
url = StringUtils.trim(url);
if (url.startsWith("feed://")) { if (url.startsWith("feed://")) {
if (BuildConfig.DEBUG) Log.d(TAG, "Replacing feed:// with http://"); if (BuildConfig.DEBUG) Log.d(TAG, "Replacing feed:// with http://");
url = url.replaceFirst("feed://", "http://"); url = url.replaceFirst("feed://", "http://");

View File

@ -43,4 +43,16 @@ public class URLCheckerTest extends AndroidTestCase {
final String out = URLChecker.prepareURL(in); final String out = URLChecker.prepareURL(in);
assertEquals("http://example.com", out); 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);
}
} }