How do I uri-decode in Kotlin JS/WASM?
# compose-web
g
How do I uri-decode in Kotlin JS/WASM?
i
Copy code
external fun decodeURI(uri:String): String
I don't see it defined in KJS so that would be how you add it
g
ah, so it is enough to declare any JavaScript function that is missing as external?
g
👍
c
you might have a look at the wrappers. https://github.com/JetBrains/kotlin-wrappers most JS apis are already avalable in the
kotlin-js
wrapper
👀 1
g
Hee, hee - thanks a lot, although I know nothing about JavaScript.
But something strange is happening with external decodeURI. This code:
Copy code
val decoded1 = decodeURI(cookies)
        val decoded2 = decodeURI(decoded1)
        debugLog("Decoded cookies 1: '$decoded1'")
        debugLog("Decoded cookies 2: '$decoded2'")
(yes - double encoded data) shows in log:
Copy code
Decoded cookies 1: 'SESSION_ID=accessToken%3D%23sya29.a0AcM612zbV5lhv_HPT_TgYFapnJqhtK_oTcyMa7FsL-SzrzANQmneWAN1l7MqTkJraTd8IyJDYA985mGtRUYRI48glqdairfJO2UDJKXFzbJ4Hx-a-FXxwmtvuhG9Wio1IyDnO0caJIGtk8pwAo-VJUQCuFz-9shUwMnSa_ZKaCgYKAY4SARMSFQHGX2MiaFZtPNPgp1-VexDLcfoA9w0175%26userId%3D%23i1'
composeApp.uninstantiated.mjs:6208 Decoded cookies 2: 'SESSION_ID=accessToken%3D%23sya29.a0AcM612zbV5lhv_HPT_TgYFapnJqhtK_oTcyMa7FsL-SzrzANQmneWAN1l7MqTkJraTd8IyJDYA985mGtRUYRI48glqdairfJO2UDJKXFzbJ4Hx-a-FXxwmtvuhG9Wio1IyDnO0caJIGtk8pwAo-VJUQCuFz-9shUwMnSa_ZKaCgYKAY4SARMSFQHGX2MiaFZtPNPgp1-VexDLcfoA9w0175%26userId%3D%23i1'
so - notthing is happening!'
c
i guess you want to
decodeURIComponent
as you do not have an URI but just a part of it.
☝️ 1
g
aaaah
😉 1
So maybe a bonus question - do you know what ktor comonent adds type annotations to fields, look at this decoded cookie:
'SESSION_ID=accessToken=#sya29.a0AcM612xBakbD6p0jtxGGVo4J6X-N2tGAFYtRMHsmcLGb3dodi9ZRXKXfgWTLnpOOSJNldIxKd6ozezL4tQHS94jE07CGqO2s0pW-zaWWmitR7If7vpAlD7SjLKF5VqN-QzEGriTtC-SHivhTiaVrEHXaXdWfRQZwc4S6ybIraCgYKAToSARMSFQHGX2Mi4bPkYdh7V06eGAZYlpoYPQ0175&userId=#i1'
it has #s for string and #i for int, I didn't put them there...
c
🤷 ask in #C0A974TJ9