Skip to content

Commit 8cf9d1c

Browse files
committed
fix the Escape semicolon
1 parent 4e12282 commit 8cf9d1c

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

color.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func ColorfulResponse(str, contenttype string) string {
5959
func ColorfulJson(str string) string {
6060
var rsli []rune
6161
var key, val, startcolor, endcolor, startsemicolon bool
62+
var prev rune
6263
for _, char := range []rune(str) {
6364
switch char {
6465
case ' ':
@@ -75,22 +76,26 @@ func ColorfulJson(str string) string {
7576
val = false
7677
rsli = append(rsli, char)
7778
case '"':
78-
if startcolor {
79+
if startsemicolon && prev == '\\' {
7980
rsli = append(rsli, char)
80-
if key {
81-
rsli = append(rsli, []rune(ColorStart(Magenta))...)
82-
} else if val {
83-
rsli = append(rsli, []rune(ColorStart(Cyan))...)
84-
}
85-
startsemicolon = true
86-
key = false
87-
val = false
88-
startcolor = false
8981
} else {
90-
rsli = append(rsli, []rune(EndColor)...)
91-
rsli = append(rsli, char)
92-
endcolor = true
93-
startsemicolon = false
82+
if startcolor {
83+
rsli = append(rsli, char)
84+
if key {
85+
rsli = append(rsli, []rune(ColorStart(Magenta))...)
86+
} else if val {
87+
rsli = append(rsli, []rune(ColorStart(Cyan))...)
88+
}
89+
startsemicolon = true
90+
key = false
91+
val = false
92+
startcolor = false
93+
} else {
94+
rsli = append(rsli, []rune(EndColor)...)
95+
rsli = append(rsli, char)
96+
endcolor = true
97+
startsemicolon = false
98+
}
9499
}
95100
case ',':
96101
if !startsemicolon {
@@ -133,6 +138,7 @@ func ColorfulJson(str string) string {
133138
}
134139
rsli = append(rsli, char)
135140
}
141+
prev = char
136142
}
137143
return string(rsli)
138144
}

0 commit comments

Comments
 (0)