From 6696a8b3ca1264ad54d270db6b23302a128f9ae0 Mon Sep 17 00:00:00 2001 From: Sorunome Date: Mon, 27 Jul 2020 07:40:25 +0000 Subject: [PATCH] Remove trailing slash in checkServer --- lib/src/client.dart | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index 5ae9947..44ad73b 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -247,7 +247,19 @@ class Client { /// Throws FormatException, TimeoutException and MatrixException on error. Future checkServer(dynamic serverUrl) async { try { - api.homeserver = (serverUrl is Uri) ? serverUrl : Uri.parse(serverUrl); + if (serverUrl is Uri) { + api.homeserver = serverUrl; + } else { + // URLs allow to have whitespace surrounding them, see https://www.w3.org/TR/2011/WD-html5-20110525/urls.html + // As we want to strip a trailing slash, though, we have to trim the url ourself + // and thus can't let Uri.parse() deal with it. + serverUrl = serverUrl.trim(); + // strip a trailing slash + if (serverUrl.endsWith('/')) { + serverUrl = serverUrl.substring(0, serverUrl.length - 1); + } + api.homeserver = Uri.parse(serverUrl); + } final versions = await api.requestSupportedVersions(); for (var i = 0; i < versions.versions.length; i++) {