From c64e15acad1b4b8e93d6e639bbb894c4650b3657 Mon Sep 17 00:00:00 2001 From: Mygod Date: Fri, 23 Mar 2018 01:32:17 -0700 Subject: [PATCH] Catch URISyntaxException --- .../github/shadowsocks/database/Profile.kt | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/mobile/src/main/java/com/github/shadowsocks/database/Profile.kt b/mobile/src/main/java/com/github/shadowsocks/database/Profile.kt index 9e8bfff6..e9beae53 100644 --- a/mobile/src/main/java/com/github/shadowsocks/database/Profile.kt +++ b/mobile/src/main/java/com/github/shadowsocks/database/Profile.kt @@ -31,6 +31,7 @@ import com.j256.ormlite.field.DataType import com.j256.ormlite.field.DatabaseField import java.io.Serializable import java.net.URI +import java.net.URISyntaxException import java.util.* class Profile : Serializable { @@ -67,14 +68,19 @@ class Profile : Serializable { profile.method = match.groupValues[1] profile.password = match.groupValues[2] // bug in Android: https://code.google.com/p/android/issues/detail?id=192855 - val javaURI = URI(it.value) - profile.host = javaURI.host ?: "" - if (profile.host.firstOrNull() == '[' && profile.host.lastOrNull() == ']') - profile.host = profile.host.substring(1, profile.host.length - 1) - profile.remotePort = javaURI.port - profile.plugin = uri.getQueryParameter(Key.plugin) - profile.name = uri.fragment ?: "" - profile + try { + val javaURI = URI(it.value) + profile.host = javaURI.host ?: "" + if (profile.host.firstOrNull() == '[' && profile.host.lastOrNull() == ']') + profile.host = profile.host.substring(1, profile.host.length - 1) + profile.remotePort = javaURI.port + profile.plugin = uri.getQueryParameter(Key.plugin) + profile.name = uri.fragment ?: "" + profile + } catch (e: URISyntaxException) { + Log.e(TAG, "Invalid URI: ${it.value}") + null + } } else { Log.e(TAG, "Unknown user info: ${it.value}") null