Parse correctly json header when a curly brace is included in a string.

Former-commit-id: 35225bc7db165825d4e5ef583324e54829695503
This commit is contained in:
Eric Coissac
2024-03-19 13:47:03 +01:00
parent b428c48353
commit 11a14b6dc8

View File

@ -17,18 +17,24 @@ func _parse_json_header_(header string, annotations obiseq.Annotation) string {
stop := -1 stop := -1
level := 0 level := 0
lh := len(header) lh := len(header)
inquote := false
for i := 0; (i < lh) && (stop < 0); i++ { 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], '{', '{') // 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 start = i
} }
if header[i] == '{' { // TODO: escaped double quotes are not considered
if start > -1 && header[i] == '"' {
inquote = !inquote
}
if header[i] == '{' && !inquote {
level++ level++
} }
if header[i] == '}' { if header[i] == '}' && !inquote {
level-- level--
} }