From f99188615531371625cb927e40770e692ef1bb20 Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Tue, 7 Nov 2023 12:10:14 +0200 Subject: [PATCH] Force json encoding to ascii Former-commit-id: b35110f3fed5fedfc03380863ece5c95a2b9d6a7 --- pkg/obiformats/json_writer.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pkg/obiformats/json_writer.go b/pkg/obiformats/json_writer.go index 0d4193b..4d8009d 100644 --- a/pkg/obiformats/json_writer.go +++ b/pkg/obiformats/json_writer.go @@ -6,6 +6,8 @@ import ( "encoding/json" "io" "os" + "strconv" + "strings" "sync" "time" @@ -15,6 +17,14 @@ import ( log "github.com/sirupsen/logrus" ) +func _UnescapeUnicodeCharactersInJSON(_jsonRaw []byte) ([]byte, error) { + str, err := strconv.Unquote(strings.Replace(strconv.Quote(string(_jsonRaw)), `\\u`, `\u`, -1)) + if err != nil { + return nil, err + } + return []byte(str), nil +} + func JSONRecord(sequence *obiseq.BioSequence) []byte { record := make(map[string]interface{}, 4) @@ -38,6 +48,12 @@ func JSONRecord(sequence *obiseq.BioSequence) []byte { log.Panicf("conversion to JSON error on sequence id %s", sequence.Id()) } + text, error = _UnescapeUnicodeCharactersInJSON(text) + + if error != nil { + log.Panicf("conversion to JSON error on sequence id %s", sequence.Id()) + } + return text }