diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/qrcode/Extensions.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/qrcode/Extensions.kt index 2f90d36140..a4efe385bb 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/qrcode/Extensions.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/verification/qrcode/Extensions.kt @@ -18,6 +18,10 @@ package im.vector.matrix.android.internal.crypto.verification.qrcode import im.vector.matrix.android.api.MatrixPatterns import im.vector.matrix.android.api.permalinks.PermalinkFactory +import java.net.URLDecoder +import java.net.URLEncoder + +private const val ENCODING = "utf-8" /** * Generate an URL to generate a QR code of the form: @@ -34,21 +38,19 @@ fun QrCodeData.toUrl(): String { return buildString { append(PermalinkFactory.createPermalink(userId)) append("?request=") - append(PermalinkFactory.escape(requestEventId)) + append(URLEncoder.encode(requestEventId, ENCODING)) append("&action=") - append(PermalinkFactory.escape(action)) + append(URLEncoder.encode(action, ENCODING)) for ((keyId, key) in keys) { - append("&key_") - append(PermalinkFactory.escape(keyId)) - append("=") - append(PermalinkFactory.escape(key)) + append("&key_$keyId=") + append(URLEncoder.encode(key, ENCODING)) } append("&secret=") - append(PermalinkFactory.escape(sharedSecret)) + append(URLEncoder.encode(sharedSecret, ENCODING)) append("&other_user_key=") - append(PermalinkFactory.escape(otherUserKey)) + append(URLEncoder.encode(otherUserKey, ENCODING)) } } @@ -82,7 +84,7 @@ fun String.toQrCodeData(): QrCodeData? { .filter { it.isNotEmpty() } val keyValues = urlParams.map { - (it.substringBefore("=") to it.substringAfter("=").let { value -> PermalinkFactory.unescape(value) }) + (it.substringBefore("=") to it.substringAfter("=").let { value -> URLDecoder.decode(value, ENCODING) }) }.toMap() val action = keyValues["action"] ?: return null diff --git a/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/verification/qrcode/QrCodeTest.kt b/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/verification/qrcode/QrCodeTest.kt index c356ee4795..3c184907a6 100644 --- a/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/verification/qrcode/QrCodeTest.kt +++ b/matrix-sdk-android/src/test/java/im/vector/matrix/android/internal/crypto/verification/qrcode/QrCodeTest.kt @@ -39,7 +39,7 @@ class QrCodeTest { otherUserKey = "otherUserKey" ) - private val basicUrl = "https://matrix.to/#/@benoit:matrix.org?request=\$azertyazerty&action=verify&key_1=abcdef&key_2=ghijql&secret=sharedSecret&other_user_key=otherUserKey" + private val basicUrl = "https://matrix.to/#/@benoit:matrix.org?request=%24azertyazerty&action=verify&key_1=abcdef&key_2=ghijql&secret=sharedSecret&other_user_key=otherUserKey" @Test fun testNominalCase() { @@ -101,7 +101,7 @@ class QrCodeTest { @Test fun testBadRequestEventId() { - basicUrl.replace("\$azertyazerty", "@azertyazerty") + basicUrl.replace("%24azertyazerty", "%32azertyazerty") .toQrCodeData() .shouldBeNull() }