Support json.RawMessage in configuration env overrides (#23610)
* support json.RawMessage in env overrides
Этот коммит содержится в:
@@ -7,6 +7,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@@ -57,7 +58,19 @@ func NewHumanizedJSONError(err error, data []byte, offset int64) *HumanizedJSONE
|
||||
}
|
||||
|
||||
func IsEmptyJSON(j json.RawMessage) bool {
|
||||
if len(j) == 0 || bytes.Equal(j, []byte("{}")) || bytes.Equal(j, []byte("\"\"")) || bytes.Equal(j, []byte("[]")) {
|
||||
if len(j) == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
// remove all whitespace
|
||||
jj := make([]byte, 0, len(j))
|
||||
for _, b := range j {
|
||||
if !unicode.IsSpace(rune(b)) {
|
||||
jj = append(jj, b)
|
||||
}
|
||||
}
|
||||
|
||||
if len(jj) == 0 || bytes.Equal(jj, []byte("{}")) || bytes.Equal(jj, []byte("\"\"")) || bytes.Equal(jj, []byte("[]")) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
||||
@@ -283,6 +283,11 @@ func TestIsJSONEmpty(t *testing.T) {
|
||||
[]byte("\"hello\""),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"whitespace still empty",
|
||||
[]byte(" \n { \t } "),
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
|
||||
Ссылка в новой задаче
Block a user