Mentions légales du service

Skip to content
Snippets Groups Projects
Commit d1705204 authored by Yannick Li's avatar Yannick Li
Browse files

Merge branch '24-escape-corretly-chars-while-communiacting-with-c-service' into 'master'

Add (un)escape to c-service adapter

Closes #24

See merge request !18
parents a1f6a145 3558b02c
No related branches found
Tags 8.13+no
1 merge request!18Add (un)escape to c-service adapter
Pipeline #214884 passed
...@@ -19,7 +19,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile ...@@ -19,7 +19,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
description = "Concordant C-Client" description = "Concordant C-Client"
group = "concordant" group = "concordant"
version = "1.1.0" version = "1.1.1"
plugins { plugins {
kotlin("multiplatform") version "1.4.20" kotlin("multiplatform") version "1.4.20"
......
...@@ -61,13 +61,19 @@ class CServiceAdapter { ...@@ -61,13 +61,19 @@ class CServiceAdapter {
fun getObject(dbName: String, serviceUrl: String, objectUId: CObjectUId, target: DeltaCRDT){ fun getObject(dbName: String, serviceUrl: String, objectUId: CObjectUId, target: DeltaCRDT){
GlobalScope.launch { GlobalScope.launch {
val client = HttpClient() val client = HttpClient()
val crdtJson = client.post<String>{ var crdtJson = client.post<String>{
url("$serviceUrl/api/get-object") url("$serviceUrl/api/get-object")
contentType(ContentType.Application.Json) contentType(ContentType.Application.Json)
body = """{"appName":"$dbName","id":"${Json.encodeToString(objectUId).replace("\"","\\\"")}"}""" body = """{"appName":"$dbName","id":"${Json.encodeToString(objectUId).replace("\"","\\\"")}"}"""
} }
client.close() client.close()
target.merge(DeltaCRDT.fromJson(crdtJson.removePrefix("\"").removeSuffix("\"").replace("""\\"""","""\""""))) crdtJson = crdtJson.removePrefix("\"").removeSuffix("\"")
crdtJson = crdtJson.replace("\\\\\\\"", "\\\\\""); // replace \\\" with \\"
crdtJson = crdtJson.replace("\\\\'", "'"); // replace \\' with '
crdtJson = crdtJson.replace("\\\\n", "\\n"); // replace \\n with \n
crdtJson = crdtJson.replace("\\\\\\", "\\\\"); // replace \\\ with \\
crdtJson = crdtJson.replace("\\\"", "\""); // replace \" with "
target.merge(DeltaCRDT.fromJson(crdtJson));
} }
} }
...@@ -80,7 +86,11 @@ class CServiceAdapter { ...@@ -80,7 +86,11 @@ class CServiceAdapter {
fun updateObject(dbName: String, serviceUrl: String, objectUId: CObjectUId, crdt: DeltaCRDT){ fun updateObject(dbName: String, serviceUrl: String, objectUId: CObjectUId, crdt: DeltaCRDT){
GlobalScope.launch { GlobalScope.launch {
val client = HttpClient() val client = HttpClient()
val crdtJson = crdt.toJson().replace("\"","\\\"") var crdtJson = crdt.toJson().replace("\\\\", "\\\\\\"); // replace \\ with \\\
crdtJson = crdtJson.replace("\\\"", "\\\\\""); // replace \" with \\"
crdtJson = crdtJson.replace("'", "\\\\'"); // replace ' with \\'
crdtJson = crdtJson.replace("\\n", "\\\\n"); // replace \n with \\n
crdtJson = crdtJson.replace("\"", "\\\""); // replace " with \"
client.post<String>{ client.post<String>{
url("$serviceUrl/api/update-object") url("$serviceUrl/api/update-object")
contentType(ContentType.Application.Json) contentType(ContentType.Application.Json)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment