mirror of
https://github.com/f-droid/fdroidclient.git
synced 2026-04-19 14:27:01 -04:00
Merge branch 'hierarchical-uris' into 'master'
Don't crash on non-hierarchical URIs in RepoUriGetter Closes acra-crash-reports#724 See merge request fdroid/fdroidclient!1354
This commit is contained in:
@@ -26,8 +26,8 @@ internal object RepoUriGetter {
|
||||
else -> it
|
||||
}
|
||||
}
|
||||
val fingerprint = uri.getQueryParameter("fingerprint")?.lowercase()?.trimEnd()
|
||||
?: uri.getQueryParameter("FINGERPRINT")?.lowercase()?.trimEnd()
|
||||
val fingerprint = uri.getQueryParameterOrNull("fingerprint")?.lowercase()?.trimEnd()
|
||||
?: uri.getQueryParameterOrNull("FINGERPRINT")?.lowercase()?.trimEnd()
|
||||
|
||||
val pathSegments = uri.pathSegments
|
||||
var username: String? = null
|
||||
@@ -78,7 +78,7 @@ internal object RepoUriGetter {
|
||||
}
|
||||
|
||||
fun isSwapUri(uri: Uri): Boolean {
|
||||
val swap = uri.getQueryParameter("swap") ?: uri.getQueryParameter("SWAP")
|
||||
val swap = uri.getQueryParameterOrNull("swap") ?: uri.getQueryParameterOrNull("SWAP")
|
||||
return swap != null && uri.scheme?.lowercase() == "http"
|
||||
}
|
||||
|
||||
@@ -86,6 +86,14 @@ internal object RepoUriGetter {
|
||||
return Uri.parse(uri.encodedFragment)
|
||||
}
|
||||
|
||||
private fun Uri.getQueryParameterOrNull(key: String): String? {
|
||||
return try {
|
||||
getQueryParameter(key)
|
||||
} catch (e: Exception) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A class for normalizing the [Repository] URI and holding an optional fingerprint
|
||||
* as well as username/password for basic authentication.
|
||||
|
||||
@@ -172,6 +172,11 @@ internal class RepoUriGetterTest {
|
||||
RepoUriGetter.getUri("")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNonHierarchicalUri() {
|
||||
RepoUriGetter.getUri("mailto:nobody@google.com") // should not crash
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSwapUri() {
|
||||
val uri =
|
||||
@@ -204,5 +209,8 @@ internal class RepoUriGetterTest {
|
||||
|
||||
val uri3 = Uri.parse("http://192.168.3.159:8888/fdroid/repo?BSSID=44:FE:3B:7F:7F:EE")
|
||||
assertFalse(RepoUriGetter.isSwapUri(uri3))
|
||||
|
||||
val uri4 = Uri.parse("mailto:nobody@google.com")
|
||||
assertFalse(RepoUriGetter.isSwapUri(uri4))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user