summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorByteHamster <ByteHamster@users.noreply.github.com>2024-05-22 10:03:59 +0200
committerGitHub <noreply@github.com>2024-05-22 10:03:59 +0200
commitbaeb0d8ced36f645397d962ba27150fc630763a4 (patch)
tree5dd499668cfbb3c70ce68b0a9fb70adc55310b9e /net
parent5f5d744e71a920585609f46024d2ce6642266852 (diff)
downloadAntennaPod-baeb0d8ced36f645397d962ba27150fc630763a4.zip
Fix UrlChecker on antennapod_local urls (#7191)
Diffstat (limited to 'net')
-rw-r--r--net/common/src/main/java/de/danoeh/antennapod/net/common/UrlChecker.java21
-rw-r--r--net/common/src/test/java/de/danoeh/antennapod/net/common/UrlCheckerTest.java2
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<String> pathSegments1 = normalizePathSegments(url1.pathSegments());
- List<String> pathSegments2 = normalizePathSegments(url2.pathSegments());
+ List<String> pathSegments1 = normalizePathSegments(url1.getPathSegments());
+ List<String> 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/"));
}
}