Skip to content

Commit

Permalink
listable: Fix incorrect unmarshaling of null to []T{null}
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Jan 8, 2025
1 parent aa7d254 commit db8125e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions common/json/badoption/listable.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package badoption

import (
"context"
"slices"

Check failure on line 5 in common/json/badoption/listable.go

View workflow job for this annotation

GitHub Actions / Linux (Go 1.20)

package slices is not in GOROOT (/opt/hostedtoolcache/go/1.20.14/x64/src/slices)

E "github.com/sagernet/sing/common/exceptions"
"github.com/sagernet/sing/common/json"
Expand All @@ -18,6 +19,9 @@ func (l Listable[T]) MarshalJSONContext(ctx context.Context) ([]byte, error) {
}

func (l *Listable[T]) UnmarshalJSONContext(ctx context.Context, content []byte) error {
if slices.Equal(content, []byte("null")) {
return nil
}
var singleItem T
err := json.UnmarshalContextDisallowUnknownFields(ctx, content, &singleItem)
if err == nil {
Expand Down

0 comments on commit db8125e

Please sign in to comment.