chat component: allow unescaped control characters (e.g. \n in json string)

The Cuberite kick message is now properly parsed
This commit is contained in:
Bixilon 2023-03-30 14:23:15 +02:00
parent 57c30d062a
commit 5b55934c9e
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 9 additions and 0 deletions

View File

@ -14,6 +14,7 @@
package de.bixilon.minosoft.util.json
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.core.json.JsonReadFeature
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.MapperFeature
import com.fasterxml.jackson.databind.PropertyNamingStrategies
@ -31,6 +32,7 @@ object Jackson {
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE)
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS)
.enable(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS)
.build()
.registerModule(
KotlinModule.Builder()

View File

@ -227,6 +227,13 @@ internal class ChatComponentTest {
assertEquals(expected, component)
}
@Test
fun `JSON not escaped new line`() {
val text = ChatComponent.of("""{"text":"Unsupported protocol version 762.""" + "\n" + """Try connecting with Minecraft 1.8.x-1.12.x"}""")
val expected = TextComponent("Unsupported protocol version 762.\nTry connecting with Minecraft 1.8.x-1.12.x")
assertEquals(text, expected)
}
private fun assertEquals(expected: ChatComponent, actual: ChatComponent) {
when (expected) {
is BaseComponent -> {