Commit c64e15ac authored by Mygod's avatar Mygod

Catch URISyntaxException

parent 9ff33ec1
...@@ -31,6 +31,7 @@ import com.j256.ormlite.field.DataType ...@@ -31,6 +31,7 @@ import com.j256.ormlite.field.DataType
import com.j256.ormlite.field.DatabaseField import com.j256.ormlite.field.DatabaseField
import java.io.Serializable import java.io.Serializable
import java.net.URI import java.net.URI
import java.net.URISyntaxException
import java.util.* import java.util.*
class Profile : Serializable { class Profile : Serializable {
...@@ -67,14 +68,19 @@ class Profile : Serializable { ...@@ -67,14 +68,19 @@ class Profile : Serializable {
profile.method = match.groupValues[1] profile.method = match.groupValues[1]
profile.password = match.groupValues[2] profile.password = match.groupValues[2]
// bug in Android: https://code.google.com/p/android/issues/detail?id=192855 // bug in Android: https://code.google.com/p/android/issues/detail?id=192855
val javaURI = URI(it.value) try {
profile.host = javaURI.host ?: "" val javaURI = URI(it.value)
if (profile.host.firstOrNull() == '[' && profile.host.lastOrNull() == ']') profile.host = javaURI.host ?: ""
profile.host = profile.host.substring(1, profile.host.length - 1) if (profile.host.firstOrNull() == '[' && profile.host.lastOrNull() == ']')
profile.remotePort = javaURI.port profile.host = profile.host.substring(1, profile.host.length - 1)
profile.plugin = uri.getQueryParameter(Key.plugin) profile.remotePort = javaURI.port
profile.name = uri.fragment ?: "" profile.plugin = uri.getQueryParameter(Key.plugin)
profile profile.name = uri.fragment ?: ""
profile
} catch (e: URISyntaxException) {
Log.e(TAG, "Invalid URI: ${it.value}")
null
}
} else { } else {
Log.e(TAG, "Unknown user info: ${it.value}") Log.e(TAG, "Unknown user info: ${it.value}")
null null
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment