From db8125ebef6fd3e0fc886d2148106ad2f3980115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Wed, 8 Jan 2025 11:04:24 +0800 Subject: [PATCH] listable: Fix incorrect unmarshaling of null to []T{null} --- common/json/badoption/listable.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/json/badoption/listable.go b/common/json/badoption/listable.go index df02217e..3b57cedb 100644 --- a/common/json/badoption/listable.go +++ b/common/json/badoption/listable.go @@ -2,6 +2,7 @@ package badoption import ( "context" + "slices" E "github.com/sagernet/sing/common/exceptions" "github.com/sagernet/sing/common/json" @@ -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 {