QRcode: Url encode the keys
This commit is contained in:
parent
2111daea52
commit
2bccd19f84
|
@ -52,7 +52,7 @@ fun QrCodeData.toUrl(): String {
|
||||||
append(URLEncoder.encode(action, ENCODING))
|
append(URLEncoder.encode(action, ENCODING))
|
||||||
|
|
||||||
for ((keyId, key) in keys) {
|
for ((keyId, key) in keys) {
|
||||||
append("&key_$keyId=")
|
append("&key_${URLEncoder.encode(keyId, ENCODING)}=")
|
||||||
append(URLEncoder.encode(key, ENCODING))
|
append(URLEncoder.encode(key, ENCODING))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ fun String.toQrCodeData(): QrCodeData? {
|
||||||
val keys = keyValues.keys
|
val keys = keyValues.keys
|
||||||
.filter { it.startsWith("key_") }
|
.filter { it.startsWith("key_") }
|
||||||
.map {
|
.map {
|
||||||
it.substringAfter("key_") to (keyValues[it] ?: return null)
|
URLDecoder.decode(it.substringAfter("key_"), ENCODING) to (keyValues[it] ?: return null)
|
||||||
}
|
}
|
||||||
.toMap()
|
.toMap()
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,29 @@ class QrCodeTest {
|
||||||
decodedData.otherUserKey shouldBeEqualTo "otherUserKey"
|
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
|
@Test
|
||||||
fun testMissingActionCase() {
|
fun testMissingActionCase() {
|
||||||
basicUrl.replace("&action=verify", "")
|
basicUrl.replace("&action=verify", "")
|
||||||
|
|
Loading…
Reference in New Issue