Browse Source

Merge pull request #39 from Skehmatics/feature/allowRfc3986Urls

Avoid java.net.URI's RFC 2396 parsing to allow more modern URLs (escaped characters in params would get unescaped after parsing).
housekeeping/remove-warnings
Antoine POPINEAU 4 years ago committed by GitHub
parent
commit
1ccfedca87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      app/src/main/java/com/github/apognu/otter/utils/Util.kt

20
app/src/main/java/com/github/apognu/otter/utils/Util.kt

@ -5,6 +5,7 @@ import android.widget.Toast @@ -5,6 +5,7 @@ import android.widget.Toast
import com.google.android.exoplayer2.util.Log
import com.preference.PowerPreference
import java.net.URI
import java.net.URL
fun Context?.toast(message: String, length: Int = Toast.LENGTH_SHORT) {
if (this != null) {
@ -20,23 +21,18 @@ fun Any.log() { @@ -20,23 +21,18 @@ fun Any.log() {
Log.d("FUNKWHALE", this.toString())
}
fun maybeNormalizeUrl(url: String?): String? {
if (url == null || url.isEmpty()) return null
fun maybeNormalizeUrl(rawUrl: String?): String? {
if (rawUrl == null || rawUrl.isEmpty()) return null
val fallbackHost = PowerPreference.getFileByName(AppContext.PREFS_CREDENTIALS).getString("hostname")
val uri = URI(url).takeIf { it.host != null } ?: URI("$fallbackHost$url")
return uri.run {
URI("https", host, path, query, null)
}.toString()
return mustNormalizeUrl(rawUrl)
}
fun mustNormalizeUrl(url: String): String {
fun mustNormalizeUrl(rawUrl: String): String {
val fallbackHost = PowerPreference.getFileByName(AppContext.PREFS_CREDENTIALS).getString("hostname")
val uri = URI(url).takeIf { it.host != null } ?: URI("$fallbackHost$url")
val uri = URI(rawUrl).takeIf { it.host != null } ?: URI("$fallbackHost$rawUrl")
return uri.run {
URI("https", host, path, query, null)
return uri.toURL().run {
URL("https", host, file)
}.toString()
}

Loading…
Cancel
Save