mirror of
https://github.com/openflocon/Flocon.git
synced 2026-04-28 10:19:33 +00:00
Fix GraphQL operationName parsing when variable values contain ampers… (#504)
This commit is contained in:
parent
b28e0dc3fb
commit
58ae88adad
2 changed files with 27 additions and 8 deletions
|
|
@ -1,6 +1,5 @@
|
|||
package com.flocon.data.remote.network.mapper
|
||||
|
||||
import com.flocon.data.remote.network.mapper.extractDomain
|
||||
import com.flocon.data.remote.network.models.BadQualityConfigDataModel
|
||||
import com.flocon.data.remote.network.models.FloconNetworkRequestDataModel
|
||||
import com.flocon.data.remote.network.models.FloconNetworkWebSocketEvent
|
||||
|
|
@ -13,7 +12,6 @@ import io.github.openflocon.domain.device.models.AppInstance
|
|||
import io.github.openflocon.domain.network.models.BadQualityConfigDomainModel
|
||||
import io.github.openflocon.domain.network.models.FloconNetworkCallDomainModel
|
||||
import io.github.openflocon.domain.network.models.MockNetworkDomainModel
|
||||
import io.ktor.server.util.url
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.net.URI
|
||||
import java.net.URLDecoder
|
||||
|
|
@ -139,12 +137,18 @@ fun extractGraphQl(decoded: FloconNetworkRequestDataModel): GraphQlExtracted? {
|
|||
decoded.url?.let { urlString ->
|
||||
try {
|
||||
val uri = URI(urlString)
|
||||
val queryParams = uri.query
|
||||
?.split("&")
|
||||
?.associate {
|
||||
val (k, v) = it.split("=")
|
||||
k to URLDecoder.decode(v, "UTF-8")
|
||||
} ?: emptyMap()
|
||||
val queryParams = uri.rawQuery?.let { rawQuery ->
|
||||
buildMap {
|
||||
for (param in rawQuery.split('&')) {
|
||||
val idx = param.indexOf('=')
|
||||
if (idx != -1) {
|
||||
val key = URLDecoder.decode(param.substring(0, idx), "UTF-8")
|
||||
val value = URLDecoder.decode(param.substring(idx + 1), "UTF-8")
|
||||
put(key, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
} ?: emptyMap()
|
||||
|
||||
val queryName = queryParams["operationName"]
|
||||
val extensions = queryParams["extensions"]
|
||||
|
|
|
|||
|
|
@ -69,4 +69,19 @@ class MapperTest {
|
|||
|
||||
assertNull(result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should extract from url when variable value contains ampersand`() {
|
||||
val decoded = FloconNetworkRequestDataModel(
|
||||
url = "https://www.ourapi.com/graphql?operationName=UserData&variables=%7B%22var1%22%3A%2212345%266789%22%7D&extensions=%7B%22persistedQuery%22%3A%7B%22version%22%3A1%2C%22sha256Hash%22%3A%22abcdef%22%7D%7D",
|
||||
requestBody = null,
|
||||
)
|
||||
|
||||
val result = extractGraphQl(decoded)
|
||||
|
||||
assertNotNull(result)
|
||||
assertIs<GraphQlExtracted.PersistedQuery>(result)
|
||||
assertEquals("UserData", result.queryName)
|
||||
assertEquals("persistedQuery", result.operationType)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue