Permalink parser should only look for fragment part

This commit is contained in:
ganfra 2018-12-20 14:13:23 +01:00
parent 9b8800ec55
commit 43dee60b92
3 changed files with 14 additions and 20 deletions

View File

@ -1,4 +1,4 @@
package im.vector.matrix.android.api.permalinks package im.vector.matrix.android.api


import java.util.* import java.util.*
import java.util.regex.Pattern import java.util.regex.Pattern
@ -36,7 +36,7 @@ object MatrixPatterns {
// Android does not support in URL so extract it. // Android does not support in URL so extract it.
private val PERMALINK_BASE_REGEX = "https://matrix\\.to/#/" 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 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 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) 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. // list of patterns to find some matrix item.
val MATRIX_PATTERNS = Arrays.asList( val MATRIX_PATTERNS = Arrays.asList(
MatrixPatterns.PATTERN_CONTAIN_MATRIX_TO_PERMALINK_ROOM_ID, PATTERN_CONTAIN_MATRIX_TO_PERMALINK_ROOM_ID,
MatrixPatterns.PATTERN_CONTAIN_MATRIX_TO_PERMALINK_ROOM_ALIAS, PATTERN_CONTAIN_MATRIX_TO_PERMALINK_ROOM_ALIAS,
MatrixPatterns.PATTERN_CONTAIN_APP_LINK_PERMALINK_ROOM_ID, PATTERN_CONTAIN_APP_LINK_PERMALINK_ROOM_ID,
MatrixPatterns.PATTERN_CONTAIN_APP_LINK_PERMALINK_ROOM_ALIAS, PATTERN_CONTAIN_APP_LINK_PERMALINK_ROOM_ALIAS,
MatrixPatterns.PATTERN_CONTAIN_MATRIX_USER_IDENTIFIER, PATTERN_CONTAIN_MATRIX_USER_IDENTIFIER,
MatrixPatterns.PATTERN_CONTAIN_MATRIX_ALIAS, PATTERN_CONTAIN_MATRIX_ALIAS,
MatrixPatterns.PATTERN_CONTAIN_MATRIX_ROOM_IDENTIFIER, PATTERN_CONTAIN_MATRIX_ROOM_IDENTIFIER,
MatrixPatterns.PATTERN_CONTAIN_MATRIX_EVENT_IDENTIFIER, PATTERN_CONTAIN_MATRIX_EVENT_IDENTIFIER,
MatrixPatterns.PATTERN_CONTAIN_MATRIX_GROUP_IDENTIFIER PATTERN_CONTAIN_MATRIX_GROUP_IDENTIFIER
) )


/** /**

View File

@ -4,6 +4,7 @@ import android.text.Spannable
import android.text.SpannableString import android.text.SpannableString
import android.text.method.LinkMovementMethod import android.text.method.LinkMovementMethod
import android.widget.TextView import android.widget.TextView
import im.vector.matrix.android.api.MatrixPatterns


object MatrixLinkify { object MatrixLinkify {



View File

@ -1,25 +1,18 @@
package im.vector.matrix.android.api.permalinks package im.vector.matrix.android.api.permalinks


import android.net.Uri import android.net.Uri
import im.vector.matrix.android.api.MatrixPatterns


object PermalinkParser { object PermalinkParser {


private const val MATRIX_NAVIGATE_TO_HOST = "matrix.to"

fun parse(uriString: String): PermalinkData { fun parse(uriString: String): PermalinkData {
val uri = Uri.parse(uriString) val uri = Uri.parse(uriString)
return parse(uri) return parse(uri)
} }


fun parse(uri: Uri): PermalinkData { fun parse(uri: Uri): PermalinkData {
val host = uri.host
val path = uri.path
val fragment = uri.fragment val fragment = uri.fragment

if (fragment.isNullOrEmpty()) {
if (path.isNullOrEmpty()
|| host.isNullOrEmpty()
|| fragment.isNullOrEmpty()
|| host != MATRIX_NAVIGATE_TO_HOST) {
return PermalinkData.FallbackLink(uri) return PermalinkData.FallbackLink(uri)
} }
// we are limiting to 2 params // we are limiting to 2 params