diff options
-rw-r--r-- | AndroidManifest.xml | 1 | ||||
-rw-r--r-- | src/de/danoeh/antennapod/util/URLChecker.java | 21 | ||||
-rw-r--r-- | src/instrumentationTest/de/test/antennapod/util/URLCheckerTest.java | 20 |
3 files changed, 32 insertions, 10 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 203d1be16..ee87cc8b5 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -293,6 +293,7 @@ <data android:scheme="itpc"/> <data android:scheme="pcast"/> <data android:scheme="feed"/> + <data android:scheme="antennapod-subscribe"/> </intent-filter> <intent-filter> diff --git a/src/de/danoeh/antennapod/util/URLChecker.java b/src/de/danoeh/antennapod/util/URLChecker.java index 9997daaf7..2352adddf 100644 --- a/src/de/danoeh/antennapod/util/URLChecker.java +++ b/src/de/danoeh/antennapod/util/URLChecker.java @@ -22,6 +22,8 @@ public final class URLChecker { */ private static final String TAG = "URLChecker"; + private static final String AP_SUBSCRIBE = "antennapod-subscribe://"; + /** * Checks if URL is valid and modifies it if necessary. * @@ -29,23 +31,24 @@ public final class URLChecker { * @return The prepared url */ 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://"); + return url.replaceFirst("feed://", "http://"); } else if (url.startsWith("pcast://")) { - if (BuildConfig.DEBUG) Log.d(TAG, "Replacing pcast:// with http://"); - url = url.replaceFirst("pcast://", "http://"); + if (BuildConfig.DEBUG) Log.d(TAG, "Removing pcast://"); + return prepareURL(StringUtils.removeStart(url, "pcast://")); } else if (url.startsWith("itpc")) { if (BuildConfig.DEBUG) Log.d(TAG, "Replacing itpc:// with http://"); - url = url.replaceFirst("itpc://", "http://"); + return url.replaceFirst("itpc://", "http://"); + } else if (url.startsWith(AP_SUBSCRIBE)) { + if (BuildConfig.DEBUG) Log.d(TAG, "Removing antennapod-subscribe://"); + return prepareURL(StringUtils.removeStart(url, AP_SUBSCRIBE)); } else if (!(url.startsWith("http://") || url.startsWith("https://"))) { if (BuildConfig.DEBUG) Log.d(TAG, "Adding http:// at the beginning of the URL"); - builder.append("http://"); + return "http://" + url; + } else { + return url; } - builder.append(url); - - return builder.toString(); } } diff --git a/src/instrumentationTest/de/test/antennapod/util/URLCheckerTest.java b/src/instrumentationTest/de/test/antennapod/util/URLCheckerTest.java index 08fd0d486..fa99303b1 100644 --- a/src/instrumentationTest/de/test/antennapod/util/URLCheckerTest.java +++ b/src/instrumentationTest/de/test/antennapod/util/URLCheckerTest.java @@ -32,7 +32,7 @@ public class URLCheckerTest extends AndroidTestCase { assertEquals("http://example.com", out); } - public void testPcastProtocol() { + public void testPcastProtocolNoScheme() { final String in = "pcast://example.com"; final String out = URLChecker.prepareURL(in); assertEquals("http://example.com", out); @@ -55,4 +55,22 @@ public class URLCheckerTest extends AndroidTestCase { final String out = URLChecker.prepareURL(in); assertEquals("http://example.com", out); } + + public void testAntennaPodSubscribeProtocolNoScheme() throws Exception { + final String in = "antennapod-subscribe://example.com"; + final String out = URLChecker.prepareURL(in); + assertEquals("http://example.com", out); + } + + public void testPcastProtocolWithScheme() { + final String in = "pcast://https://example.com"; + final String out = URLChecker.prepareURL(in); + assertEquals("https://example.com", out); + } + + public void testAntennaPodSubscribeProtocolWithScheme() throws Exception { + final String in = "antennapod-subscribe://https://example.com"; + final String out = URLChecker.prepareURL(in); + assertEquals("https://example.com", out); + } } |