From 71f8ce001d682468a2021f64ae087df68d7b4e14 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 22 May 2019 15:23:36 +0200 Subject: [PATCH] Fix Crash when connecting to a homeserver URL with a subpath (Fixes #133) --- .../api/auth/data/HomeServerConnectionConfig.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/data/HomeServerConnectionConfig.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/data/HomeServerConnectionConfig.kt index bca7d480c3..f231d3f1bd 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/data/HomeServerConnectionConfig.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/auth/data/HomeServerConnectionConfig.kt @@ -70,11 +70,11 @@ data class HomeServerConnectionConfig( if (hsUri.scheme != "http" && hsUri.scheme != "https") { throw RuntimeException("Invalid home server URI: " + hsUri) } - // remove trailing / - homeServerUri = if (hsUri.toString().endsWith("/")) { + // ensure trailing / + homeServerUri = if (!hsUri.toString().endsWith("/")) { try { val url = hsUri.toString() - Uri.parse(url.substring(0, url.length - 1)) + Uri.parse("$url/") } catch (e: Exception) { throw RuntimeException("Invalid home server URI: $hsUri") } @@ -96,11 +96,11 @@ data class HomeServerConnectionConfig( if (identityServerUri.scheme != "http" && identityServerUri.scheme != "https") { throw RuntimeException("Invalid identity server URI: $identityServerUri") } - // remove trailing / - if (identityServerUri.toString().endsWith("/")) { + // ensure trailing / + if (!identityServerUri.toString().endsWith("/")) { try { val url = identityServerUri.toString() - this.identityServerUri = Uri.parse(url.substring(0, url.length - 1)) + this.identityServerUri = Uri.parse("$url/") } catch (e: Exception) { throw RuntimeException("Invalid identity server URI: $identityServerUri") }