From baeb0d8ced36f645397d962ba27150fc630763a4 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Wed, 22 May 2024 10:03:59 +0200 Subject: Fix UrlChecker on antennapod_local urls (#7191) --- .../de/danoeh/antennapod/net/common/UrlChecker.java | 21 +++++++++++---------- .../antennapod/net/common/UrlCheckerTest.java | 2 ++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/net/common/src/main/java/de/danoeh/antennapod/net/common/UrlChecker.java b/net/common/src/main/java/de/danoeh/antennapod/net/common/UrlChecker.java index 4eb1fd6a5..d66f8e74a 100644 --- a/net/common/src/main/java/de/danoeh/antennapod/net/common/UrlChecker.java +++ b/net/common/src/main/java/de/danoeh/antennapod/net/common/UrlChecker.java @@ -5,8 +5,6 @@ import android.text.TextUtils; import androidx.annotation.NonNull; import android.util.Log; -import okhttp3.HttpUrl; - import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.ArrayList; @@ -106,20 +104,23 @@ public final class UrlChecker { } public static boolean urlEquals(String string1, String string2) { - HttpUrl url1 = HttpUrl.parse(string1); - HttpUrl url2 = HttpUrl.parse(string2); - if (!url1.host().equals(url2.host())) { + Uri url1 = Uri.parse(string1); + Uri url2 = Uri.parse(string2); + if (url1 == null || url2 == null || url1.getHost() == null || url2.getHost() == null) { + return string1.equals(string2); // Unable to parse url properly + } + if (!url1.getHost().toLowerCase(Locale.ROOT).equals(url2.getHost().toLowerCase(Locale.ROOT))) { return false; } - List pathSegments1 = normalizePathSegments(url1.pathSegments()); - List pathSegments2 = normalizePathSegments(url2.pathSegments()); + List pathSegments1 = normalizePathSegments(url1.getPathSegments()); + List pathSegments2 = normalizePathSegments(url2.getPathSegments()); if (!pathSegments1.equals(pathSegments2)) { return false; } - if (TextUtils.isEmpty(url1.query())) { - return TextUtils.isEmpty(url2.query()); + if (TextUtils.isEmpty(url1.getQuery())) { + return TextUtils.isEmpty(url2.getQuery()); } - return url1.query().equals(url2.query()); + return url1.getQuery().equals(url2.getQuery()); } /** diff --git a/net/common/src/test/java/de/danoeh/antennapod/net/common/UrlCheckerTest.java b/net/common/src/test/java/de/danoeh/antennapod/net/common/UrlCheckerTest.java index ba9f1dcbb..a00ae6dcb 100644 --- a/net/common/src/test/java/de/danoeh/antennapod/net/common/UrlCheckerTest.java +++ b/net/common/src/test/java/de/danoeh/antennapod/net/common/UrlCheckerTest.java @@ -162,6 +162,7 @@ public class UrlCheckerTest { assertTrue(UrlChecker.urlEquals("https://example.com/?", "https://example.com")); assertTrue(UrlChecker.urlEquals("https://Example.com", "https://example.com")); assertTrue(UrlChecker.urlEquals("https://example.com/test", "https://example.com/Test")); + assertTrue(UrlChecker.urlEquals("antennapod_local:abc", "antennapod_local:abc")); } @Test @@ -171,5 +172,6 @@ public class UrlCheckerTest { assertFalse(UrlChecker.urlEquals("https://example.com/", "https://otherpodcast.example.com/")); assertFalse(UrlChecker.urlEquals("https://www.example.com/?id=42&a=b", "https://www.example.com/?id=43&a=b")); assertFalse(UrlChecker.urlEquals("https://example.com/podcast%25test", "https://example.com/podcast test")); + assertFalse(UrlChecker.urlEquals("antennapod_local:abc", "https://example.com/")); } } -- cgit v1.2.3