updated dependencies and go
This commit is contained in:
@@ -108,11 +108,11 @@ func (u unmarshalerText) MarshalText() ([]byte, error) {
|
||||
}
|
||||
|
||||
func (u *unmarshalerText) UnmarshalText(b []byte) error {
|
||||
pos := bytes.IndexByte(b, ':')
|
||||
if pos == -1 {
|
||||
before, after, ok := bytes.Cut(b, []byte{':'})
|
||||
if !ok {
|
||||
return errors.New("missing separator")
|
||||
}
|
||||
u.A, u.B = string(b[:pos]), string(b[pos+1:])
|
||||
u.A, u.B = string(before), string(after)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ type ustructText struct {
|
||||
type u8marshal uint8
|
||||
|
||||
func (u8 u8marshal) MarshalText() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf("u%d", u8)), nil
|
||||
return fmt.Appendf(nil, "u%d", u8), nil
|
||||
}
|
||||
|
||||
var errMissingU8Prefix = errors.New("missing 'u' prefix")
|
||||
@@ -275,7 +275,7 @@ func (unexportedWithMethods) F() {}
|
||||
type byteWithMarshalJSON byte
|
||||
|
||||
func (b byteWithMarshalJSON) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`"Z%.2x"`, byte(b))), nil
|
||||
return fmt.Appendf(nil, `"Z%.2x"`, byte(b)), nil
|
||||
}
|
||||
|
||||
func (b *byteWithMarshalJSON) UnmarshalJSON(data []byte) error {
|
||||
@@ -303,7 +303,7 @@ func (b *byteWithPtrMarshalJSON) UnmarshalJSON(data []byte) error {
|
||||
type byteWithMarshalText byte
|
||||
|
||||
func (b byteWithMarshalText) MarshalText() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`Z%.2x`, byte(b))), nil
|
||||
return fmt.Appendf(nil, `Z%.2x`, byte(b)), nil
|
||||
}
|
||||
|
||||
func (b *byteWithMarshalText) UnmarshalText(data []byte) error {
|
||||
@@ -331,7 +331,7 @@ func (b *byteWithPtrMarshalText) UnmarshalText(data []byte) error {
|
||||
type intWithMarshalJSON int
|
||||
|
||||
func (b intWithMarshalJSON) MarshalJSON() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`"Z%.2x"`, int(b))), nil
|
||||
return fmt.Appendf(nil, `"Z%.2x"`, int(b)), nil
|
||||
}
|
||||
|
||||
func (b *intWithMarshalJSON) UnmarshalJSON(data []byte) error {
|
||||
@@ -359,7 +359,7 @@ func (b *intWithPtrMarshalJSON) UnmarshalJSON(data []byte) error {
|
||||
type intWithMarshalText int
|
||||
|
||||
func (b intWithMarshalText) MarshalText() ([]byte, error) {
|
||||
return []byte(fmt.Sprintf(`Z%.2x`, int(b))), nil
|
||||
return fmt.Appendf(nil, `Z%.2x`, int(b)), nil
|
||||
}
|
||||
|
||||
func (b *intWithMarshalText) UnmarshalText(data []byte) error {
|
||||
|
||||
+5
-13
@@ -177,7 +177,7 @@ type IndentOpt struct {
|
||||
|
||||
// MarshalSafeCollections is like Marshal except it will marshal nil maps and
|
||||
// slices as '{}' and '[]' respectfully instead of 'null'
|
||||
func MarshalSafeCollections(v interface{}, nilSafeSlices bool, nilSafeMaps bool, indent *IndentOpt, filter *string) ([]byte, error) {
|
||||
func MarshalSafeCollections(v any, nilSafeSlices bool, nilSafeMaps bool, indent *IndentOpt, filter *string) ([]byte, error) {
|
||||
e := &encodeState{}
|
||||
err := e.marshal(v, encOpts{escapeHTML: true, nilSafeSlices: nilSafeSlices, nilSafeMaps: nilSafeMaps, filter: filter})
|
||||
if err != nil {
|
||||
@@ -891,7 +891,7 @@ func (se sliceEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) {
|
||||
// Here we use a struct to memorize the pointer to the first element of the slice
|
||||
// and its length.
|
||||
ptr := struct {
|
||||
ptr interface{} // always an unsafe.Pointer, but avoids a dependency on package unsafe
|
||||
ptr any // always an unsafe.Pointer, but avoids a dependency on package unsafe
|
||||
len int
|
||||
}{v.UnsafePointer(), v.Len()}
|
||||
if _, ok := e.ptrSeen[ptr]; ok {
|
||||
@@ -923,7 +923,7 @@ type arrayEncoder struct {
|
||||
func (ae arrayEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) {
|
||||
e.WriteByte('[')
|
||||
n := v.Len()
|
||||
for i := 0; i < n; i++ {
|
||||
for i := range n {
|
||||
if i > 0 {
|
||||
e.WriteByte(',')
|
||||
}
|
||||
@@ -1075,10 +1075,7 @@ func appendString[Bytes []byte | string](dst []byte, src Bytes, escapeHTML bool)
|
||||
// For now, cast only a small portion of byte slices to a string
|
||||
// so that it can be stack allocated. This slows down []byte slightly
|
||||
// due to the extra copy, but keeps string performance roughly the same.
|
||||
n := len(src) - i
|
||||
if n > utf8.UTFMax {
|
||||
n = utf8.UTFMax
|
||||
}
|
||||
n := min(len(src)-i, utf8.UTFMax)
|
||||
c, size := utf8.DecodeRuneInString(string(src[i : i+n]))
|
||||
if c == utf8.RuneError && size == 1 {
|
||||
dst = append(dst, src[start:i]...)
|
||||
@@ -1130,12 +1127,7 @@ type field struct {
|
||||
type jsonfilter []string
|
||||
|
||||
func (j jsonfilter) Contains(t string) bool {
|
||||
for _, tag := range j {
|
||||
if t == tag {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(j, t)
|
||||
}
|
||||
|
||||
// typeFields returns a list of fields that JSON should recognize for the given type.
|
||||
|
||||
+14
-15
@@ -41,7 +41,7 @@ type Optionals struct {
|
||||
Uo uint `json:"uo,omitempty"`
|
||||
|
||||
Str struct{} `json:"str"`
|
||||
Sto struct{} `json:"sto,omitempty"`
|
||||
Sto struct{} `json:"sto"`
|
||||
}
|
||||
|
||||
func TestOmitEmpty(t *testing.T) {
|
||||
@@ -1166,8 +1166,7 @@ func TestMarshalUncommonFieldNames(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMarshalerError(t *testing.T) {
|
||||
s := "test variable"
|
||||
st := reflect.TypeOf(s)
|
||||
st := reflect.TypeFor[string]()
|
||||
const errText = "json: test error"
|
||||
|
||||
tests := []struct {
|
||||
@@ -1222,18 +1221,18 @@ func TestIssue63379(t *testing.T) {
|
||||
|
||||
func TestMarshalSafeCollections(t *testing.T) {
|
||||
var (
|
||||
nilSlice []interface{}
|
||||
pNilSlice *[]interface{}
|
||||
nilMap map[string]interface{}
|
||||
pNilMap *map[string]interface{}
|
||||
nilSlice []any
|
||||
pNilSlice *[]any
|
||||
nilMap map[string]any
|
||||
pNilMap *map[string]any
|
||||
)
|
||||
|
||||
type (
|
||||
nilSliceStruct struct {
|
||||
NilSlice []interface{} `json:"nil_slice"`
|
||||
NilSlice []any `json:"nil_slice"`
|
||||
}
|
||||
nilMapStruct struct {
|
||||
NilMap map[string]interface{} `json:"nil_map"`
|
||||
NilMap map[string]any `json:"nil_map"`
|
||||
}
|
||||
testWithFilter struct {
|
||||
Test1 string `json:"test1" jsonfilter:"FILTERONE"`
|
||||
@@ -1242,19 +1241,19 @@ func TestMarshalSafeCollections(t *testing.T) {
|
||||
)
|
||||
|
||||
tests := []struct {
|
||||
in interface{}
|
||||
in any
|
||||
want string
|
||||
}{
|
||||
{nilSlice, "[]"},
|
||||
{[]interface{}{}, "[]"},
|
||||
{make([]interface{}, 0), "[]"},
|
||||
{[]any{}, "[]"},
|
||||
{make([]any, 0), "[]"},
|
||||
{[]int{1, 2, 3}, "[1,2,3]"},
|
||||
{pNilSlice, "null"},
|
||||
{nilSliceStruct{}, "{\"nil_slice\":[]}"},
|
||||
{nilMap, "{}"},
|
||||
{map[string]interface{}{}, "{}"},
|
||||
{make(map[string]interface{}, 0), "{}"},
|
||||
{map[string]interface{}{"1": 1, "2": 2, "3": 3}, "{\"1\":1,\"2\":2,\"3\":3}"},
|
||||
{map[string]any{}, "{}"},
|
||||
{make(map[string]any, 0), "{}"},
|
||||
{map[string]any{"1": 1, "2": 2, "3": 3}, "{\"1\":1,\"2\":2,\"3\":3}"},
|
||||
{pNilMap, "null"},
|
||||
{nilMapStruct{}, "{\"nil_map\":{}}"},
|
||||
{testWithFilter{}, "{\"test1\":\"\"}"},
|
||||
|
||||
+4
-4
@@ -28,10 +28,10 @@ func FuzzUnmarshalJSON(f *testing.F) {
|
||||
}`))
|
||||
|
||||
f.Fuzz(func(t *testing.T, b []byte) {
|
||||
for _, typ := range []func() interface{}{
|
||||
func() interface{} { return new(interface{}) },
|
||||
func() interface{} { return new(map[string]interface{}) },
|
||||
func() interface{} { return new([]interface{}) },
|
||||
for _, typ := range []func() any{
|
||||
func() any { return new(any) },
|
||||
func() any { return new(map[string]any) },
|
||||
func() any { return new([]any) },
|
||||
} {
|
||||
i := typ()
|
||||
if err := Unmarshal(b, i); err != nil {
|
||||
|
||||
+1
-1
@@ -90,7 +90,7 @@ func appendCompact(dst, src []byte, escape bool) ([]byte, error) {
|
||||
func appendNewline(dst []byte, prefix, indent string, depth int) []byte {
|
||||
dst = append(dst, '\n')
|
||||
dst = append(dst, prefix...)
|
||||
for i := 0; i < depth; i++ {
|
||||
for range depth {
|
||||
dst = append(dst, indent...)
|
||||
}
|
||||
return dst
|
||||
|
||||
+3
-12
@@ -210,10 +210,7 @@ func diff(t *testing.T, a, b []byte) {
|
||||
t.Helper()
|
||||
for i := 0; ; i++ {
|
||||
if i >= len(a) || i >= len(b) || a[i] != b[i] {
|
||||
j := i - 10
|
||||
if j < 0 {
|
||||
j = 0
|
||||
}
|
||||
j := max(i-10, 0)
|
||||
t.Errorf("diverge at %d: «%s» vs «%s»", i, trim(a[j:]), trim(b[j:]))
|
||||
return
|
||||
}
|
||||
@@ -274,10 +271,7 @@ func genString(stddev float64) string {
|
||||
}
|
||||
|
||||
func genArray(n int) []any {
|
||||
f := int(math.Abs(rand.NormFloat64()) * math.Min(10, float64(n/2)))
|
||||
if f > n {
|
||||
f = n
|
||||
}
|
||||
f := min(int(math.Abs(rand.NormFloat64())*math.Min(10, float64(n/2))), n)
|
||||
if f < 1 {
|
||||
f = 1
|
||||
}
|
||||
@@ -289,10 +283,7 @@ func genArray(n int) []any {
|
||||
}
|
||||
|
||||
func genMap(n int) map[string]any {
|
||||
f := int(math.Abs(rand.NormFloat64()) * math.Min(10, float64(n/2)))
|
||||
if f > n {
|
||||
f = n
|
||||
}
|
||||
f := min(int(math.Abs(rand.NormFloat64())*math.Min(10, float64(n/2))), n)
|
||||
if n > 0 && f == 0 {
|
||||
f = 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user