From 11a14b6dc8186e1cae8a97a57e6afe0f02a06a68 Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Tue, 19 Mar 2024 13:47:03 +0100 Subject: [PATCH] Parse correctly json header when a curly brace is included in a string. Former-commit-id: 35225bc7db165825d4e5ef583324e54829695503 --- pkg/obiformats/fastseq_json_header.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/obiformats/fastseq_json_header.go b/pkg/obiformats/fastseq_json_header.go index 72f92a3..915ed0d 100644 --- a/pkg/obiformats/fastseq_json_header.go +++ b/pkg/obiformats/fastseq_json_header.go @@ -17,18 +17,24 @@ func _parse_json_header_(header string, annotations obiseq.Annotation) string { stop := -1 level := 0 lh := len(header) + inquote := false for i := 0; (i < lh) && (stop < 0); i++ { // fmt.Printf("[%d,%d-%d] : %d (%c) (%d,%c)\n", i, start, stop, header[i], header[i], '{', '{') - if level == 0 && header[i] == '{' { + if level == 0 && header[i] == '{' && !inquote { start = i } - if header[i] == '{' { + // TODO: escaped double quotes are not considered + if start > -1 && header[i] == '"' { + inquote = !inquote + } + + if header[i] == '{' && !inquote { level++ } - if header[i] == '}' { + if header[i] == '}' && !inquote { level-- }