From 568612fc703a821cd670b05542a58f972da513dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Thu, 1 Jan 2026 18:35:44 +0800 Subject: [PATCH] Fix duplicate tag detection for empty tags Closes https://github.com/SagerNet/sing-box/issues/3665 --- option/options.go | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/option/options.go b/option/options.go index c964998b..8bebd48f 100644 --- a/option/options.go +++ b/option/options.go @@ -5,6 +5,7 @@ import ( "context" E "github.com/sagernet/sing/common/exceptions" + F "github.com/sagernet/sing/common/format" "github.com/sagernet/sing/common/json" ) @@ -60,37 +61,40 @@ func checkOptions(options *Options) error { func checkInbounds(inbounds []Inbound) error { seen := make(map[string]bool) - for _, inbound := range inbounds { - if inbound.Tag == "" { - continue + for i, inbound := range inbounds { + tag := inbound.Tag + if tag == "" { + tag = F.ToString(i) } - if seen[inbound.Tag] { - return E.New("duplicate inbound tag: ", inbound.Tag) + if seen[tag] { + return E.New("duplicate inbound tag: ", tag) } - seen[inbound.Tag] = true + seen[tag] = true } return nil } func checkOutbounds(outbounds []Outbound, endpoints []Endpoint) error { seen := make(map[string]bool) - for _, outbound := range outbounds { - if outbound.Tag == "" { - continue + for i, outbound := range outbounds { + tag := outbound.Tag + if tag == "" { + tag = F.ToString(i) } - if seen[outbound.Tag] { - return E.New("duplicate outbound/endpoint tag: ", outbound.Tag) + if seen[tag] { + return E.New("duplicate outbound/endpoint tag: ", tag) } - seen[outbound.Tag] = true + seen[tag] = true } - for _, endpoint := range endpoints { - if endpoint.Tag == "" { - continue + for i, endpoint := range endpoints { + tag := endpoint.Tag + if tag == "" { + tag = F.ToString(i) } - if seen[endpoint.Tag] { - return E.New("duplicate outbound/endpoint tag: ", endpoint.Tag) + if seen[tag] { + return E.New("duplicate outbound/endpoint tag: ", tag) } - seen[endpoint.Tag] = true + seen[tag] = true } return nil }