From 1161dcb2999a6a74ab88180d52281a17b3365e4f Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 4 Dec 2020 08:31:14 +0100 Subject: [PATCH] PreviewUrl: protocol is mandatory (exclude rstp://) --- .../matrix/android/sdk/internal/session/media/UrlsExtractor.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/UrlsExtractor.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/UrlsExtractor.kt index b6cea04600..b7f9a88845 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/UrlsExtractor.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/media/UrlsExtractor.kt @@ -25,6 +25,7 @@ import org.matrix.android.sdk.api.session.room.model.message.MessageType import javax.inject.Inject internal class UrlsExtractor @Inject constructor() { + // Sadly Patterns.WEB_URL_WITH_PROTOCOL is not public so filter the protocol later private val urlRegex = Patterns.WEB_URL.toRegex() fun extract(event: Event): List { @@ -35,6 +36,7 @@ internal class UrlsExtractor @Inject constructor() { ?.body ?.let { urlRegex.findAll(it) } ?.map { it.value } + ?.filter { it.startsWith("https://") || it.startsWith("http://") } ?.distinct() ?.toList() .orEmpty()