Skip to content

Commit

Permalink
fix: keep key sorting under "Unicode JSON" format tiny-craft#158
Browse files Browse the repository at this point in the history
  • Loading branch information
tiny-craft committed Feb 27, 2024
1 parent 3a799b7 commit bb4ab10
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions backend/utils/convert/unicode_json_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package convutil
import (
"bytes"
"encoding/json"
"strconv"
"strings"
"unicode"
"unicode/utf16"
Expand All @@ -21,7 +22,7 @@ func (UnicodeJsonConvert) Decode(str string) (string, bool) {
(strings.HasPrefix(trimedStr, "[") && strings.HasSuffix(trimedStr, "]")) {
var out bytes.Buffer
if err := json.Indent(&out, []byte(trimedStr), "", " "); err == nil {
if quoteStr, ok := UnquoteUnicodeJson([]byte(trimedStr)); ok {
if quoteStr, ok := UnquoteUnicodeJson(out.Bytes()); ok {
return string(quoteStr), true
}
}
Expand Down Expand Up @@ -50,9 +51,7 @@ func UnquoteUnicodeJson(s []byte) ([]byte, bool) {
if s[r+offset] == '"' && s[r+offset-1] != '\\' {
offset += 1
if ub, ok := unquoteBytes(s[r : r+offset]); ok {
unquoted.WriteByte('"')
unquoted.Write(ub)
unquoted.WriteByte('"')
unquoted.WriteString(strconv.Quote(string(ub)))
} else {
return nil, false
}
Expand Down

0 comments on commit bb4ab10

Please sign in to comment.