Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json: enabled lenient UTF encoding #1735

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions atlas-json/src/main/scala/com/netflix/atlas/json/Json.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.fasterxml.jackson.core.json.JsonWriteFeature
import com.fasterxml.jackson.databind.*
import com.fasterxml.jackson.databind.module.SimpleModule
import com.fasterxml.jackson.dataformat.smile.SmileFactory
import com.fasterxml.jackson.dataformat.smile.SmileGenerator
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.scala.DefaultScalaModule
Expand Down Expand Up @@ -75,6 +76,7 @@ object Json {
.builder()
.enable(StreamReadFeature.AUTO_CLOSE_SOURCE)
.enable(StreamWriteFeature.AUTO_CLOSE_TARGET)
.enable(SmileGenerator.Feature.LENIENT_UTF_ENCODING)
.build()

private val jsonMapper = newMapper(jsonFactory)
Expand Down
10 changes: 10 additions & 0 deletions atlas-json/src/test/scala/com/netflix/atlas/json/JsonSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.fasterxml.jackson.core.JsonParseException
import com.fasterxml.jackson.core.JsonToken
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.databind.node.ObjectNode
import munit.FunSuite

import java.time.Instant
Expand Down Expand Up @@ -448,6 +449,15 @@ class JsonSuite extends FunSuite {
assertEquals(json, """{"name":"name","values":[]}""")
}

test("unmatched surrogate pairs") {
val json = "{\"test\": 1, \"test\uD83D\": 2}"
val jsonNode = Json.decode[ObjectNode](json)
val smile = Json.smileEncode(jsonNode)
val smileNode = Json.smileDecode[ObjectNode](smile)
val expected = Json.decode[ObjectNode](json.replace('\uD83D', '\uFFFD'))
assertEquals(smileNode, expected)
}

test("decode from JsonData") {
def parse(json: String): List[JsonSuiteSimple] = {
val node = Json.decode[JsonNode](json)
Expand Down
Loading