From 43dee60b9266b8a5f6246505762fe144c761025e Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 20 Dec 2018 14:13:23 +0100 Subject: [PATCH] Permalink parser should only look for fragment part --- .../api/{permalinks => }/MatrixPatterns.kt | 22 +++++++++---------- .../android/api/permalinks/MatrixLinkify.kt | 1 + .../android/api/permalinks/PermalinkParser.kt | 11 ++-------- 3 files changed, 14 insertions(+), 20 deletions(-) rename matrix-sdk-android/src/main/java/im/vector/matrix/android/api/{permalinks => }/MatrixPatterns.kt (86%) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/permalinks/MatrixPatterns.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/MatrixPatterns.kt similarity index 86% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/api/permalinks/MatrixPatterns.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/api/MatrixPatterns.kt index 1140b5df..13269c4b 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/permalinks/MatrixPatterns.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/MatrixPatterns.kt @@ -1,4 +1,4 @@ -package im.vector.matrix.android.api.permalinks +package im.vector.matrix.android.api import java.util.* import java.util.regex.Pattern @@ -36,7 +36,7 @@ object MatrixPatterns { // Android does not support in URL so extract it. private val PERMALINK_BASE_REGEX = "https://matrix\\.to/#/" private val APP_BASE_REGEX = "https://[A-Z0-9.-]+\\.[A-Z]{2,}/[A-Z]{3,}/#/room/" - private val SEP_REGEX = "/" + val SEP_REGEX = "/" private val LINK_TO_ROOM_ID_REGEXP = PERMALINK_BASE_REGEX + MATRIX_ROOM_IDENTIFIER_REGEX + SEP_REGEX + MATRIX_EVENT_IDENTIFIER_REGEX val PATTERN_CONTAIN_MATRIX_TO_PERMALINK_ROOM_ID = Pattern.compile(LINK_TO_ROOM_ID_REGEXP, Pattern.CASE_INSENSITIVE) @@ -52,15 +52,15 @@ object MatrixPatterns { // list of patterns to find some matrix item. val MATRIX_PATTERNS = Arrays.asList( - MatrixPatterns.PATTERN_CONTAIN_MATRIX_TO_PERMALINK_ROOM_ID, - MatrixPatterns.PATTERN_CONTAIN_MATRIX_TO_PERMALINK_ROOM_ALIAS, - MatrixPatterns.PATTERN_CONTAIN_APP_LINK_PERMALINK_ROOM_ID, - MatrixPatterns.PATTERN_CONTAIN_APP_LINK_PERMALINK_ROOM_ALIAS, - MatrixPatterns.PATTERN_CONTAIN_MATRIX_USER_IDENTIFIER, - MatrixPatterns.PATTERN_CONTAIN_MATRIX_ALIAS, - MatrixPatterns.PATTERN_CONTAIN_MATRIX_ROOM_IDENTIFIER, - MatrixPatterns.PATTERN_CONTAIN_MATRIX_EVENT_IDENTIFIER, - MatrixPatterns.PATTERN_CONTAIN_MATRIX_GROUP_IDENTIFIER + PATTERN_CONTAIN_MATRIX_TO_PERMALINK_ROOM_ID, + PATTERN_CONTAIN_MATRIX_TO_PERMALINK_ROOM_ALIAS, + PATTERN_CONTAIN_APP_LINK_PERMALINK_ROOM_ID, + PATTERN_CONTAIN_APP_LINK_PERMALINK_ROOM_ALIAS, + PATTERN_CONTAIN_MATRIX_USER_IDENTIFIER, + PATTERN_CONTAIN_MATRIX_ALIAS, + PATTERN_CONTAIN_MATRIX_ROOM_IDENTIFIER, + PATTERN_CONTAIN_MATRIX_EVENT_IDENTIFIER, + PATTERN_CONTAIN_MATRIX_GROUP_IDENTIFIER ) /** diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/permalinks/MatrixLinkify.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/permalinks/MatrixLinkify.kt index ff72254f..66c1d32e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/permalinks/MatrixLinkify.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/permalinks/MatrixLinkify.kt @@ -4,6 +4,7 @@ import android.text.Spannable import android.text.SpannableString import android.text.method.LinkMovementMethod import android.widget.TextView +import im.vector.matrix.android.api.MatrixPatterns object MatrixLinkify { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/permalinks/PermalinkParser.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/permalinks/PermalinkParser.kt index 07cba499..257c0a76 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/permalinks/PermalinkParser.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/permalinks/PermalinkParser.kt @@ -1,25 +1,18 @@ package im.vector.matrix.android.api.permalinks import android.net.Uri +import im.vector.matrix.android.api.MatrixPatterns object PermalinkParser { - private const val MATRIX_NAVIGATE_TO_HOST = "matrix.to" - fun parse(uriString: String): PermalinkData { val uri = Uri.parse(uriString) return parse(uri) } fun parse(uri: Uri): PermalinkData { - val host = uri.host - val path = uri.path val fragment = uri.fragment - - if (path.isNullOrEmpty() - || host.isNullOrEmpty() - || fragment.isNullOrEmpty() - || host != MATRIX_NAVIGATE_TO_HOST) { + if (fragment.isNullOrEmpty()) { return PermalinkData.FallbackLink(uri) } // we are limiting to 2 params