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 36b1a7b86b..5f21ecf18e 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 @@ -52,7 +52,7 @@ fun QrCodeData.toUrl(): String { append(URLEncoder.encode(action, ENCODING)) for ((keyId, key) in keys) { - append("&key_$keyId=") + append("&key_${URLEncoder.encode(keyId, ENCODING)}=") append(URLEncoder.encode(key, ENCODING)) } @@ -105,7 +105,7 @@ fun String.toQrCodeData(): QrCodeData? { val keys = keyValues.keys .filter { it.startsWith("key_") } .map { - it.substringAfter("key_") to (keyValues[it] ?: return null) + URLDecoder.decode(it.substringAfter("key_"), ENCODING) to (keyValues[it] ?: return null) } .toMap() 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 3c184907a6..9ef28a2aab 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 @@ -84,6 +84,29 @@ class QrCodeTest { decodedData.otherUserKey shouldBeEqualTo "otherUserKey" } + @Test + fun testUrlCharInKeys() { + val url = basicQrCodeData + .copy( + keys = mapOf( + "/=" to "abcdef", + "&?" to "ghijql" + ) + ) + .toUrl() + + url shouldBeEqualTo basicUrl + .replace("key_1=abcdef", "key_%2F%3D=abcdef") + .replace("key_2=ghijql", "key_%26%3F=ghijql") + + val decodedData = url.toQrCodeData() + + decodedData.shouldNotBeNull() + + decodedData.keys["/="]?.shouldBeEqualTo("abcdef") + decodedData.keys["&&"]?.shouldBeEqualTo("ghijql") + } + @Test fun testMissingActionCase() { basicUrl.replace("&action=verify", "")