Skip to content

Commit 148606c

Browse files
committed
fix(model-client): wrong encoding/decoding of spaces in JS
MODELIX-515
1 parent a412bc9 commit 148606c

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

model-client/src/commonTest/kotlin/org/modelix/model/SerializationUtilEscapeTest.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ class SerializationUtilEscapeTest {
2222
assertEquals("", SerializationUtil.escape(""))
2323
}
2424

25+
@Test
26+
fun escape_space() {
27+
assertEquals("+", SerializationUtil.escape(" "))
28+
}
29+
30+
@Test
31+
fun unescape_space() {
32+
assertEquals(" ", SerializationUtil.unescape("+"))
33+
}
34+
2535
@Test
2636
fun unescape_emptyString() {
2737
assertEquals("", SerializationUtil.unescape(""))

model-datastructure/src/jsMain/kotlin/org/modelix/model/persistent/SerializationUtil.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ actual object SerializationUtil {
1818
if (value == null) {
1919
return NULL_ENCODING
2020
}
21-
return encodeURIComponent(value).map { SPECIAL_ENCODING[it] ?: it.toString() }.joinToString(separator = "")
21+
return encodeURIComponent(value).asSequence()
22+
.joinToString(separator = "") { SPECIAL_ENCODING[it] ?: it.toString() }
23+
.replace("%20", "+")
2224
}
2325

2426
actual fun unescape(value: String?): String? {
2527
if (value == NULL_ENCODING) {
2628
return null
2729
}
28-
return decodeURIComponent(value!!)
30+
return decodeURIComponent(value!!.replace("+", " "))
2931
}
3032

3133
actual fun longToHex(value: Long): String {

0 commit comments

Comments
 (0)