From eb2d364fcfeb7cfb4b17a666e888ab547d7ea73c Mon Sep 17 00:00:00 2001 From: problematicconsumer Date: Fri, 19 Jan 2024 22:19:53 +0330 Subject: [PATCH] Fix json parser for files with comment --- config/parser.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/config/parser.go b/config/parser.go index c29c03a..a64fd70 100644 --- a/config/parser.go +++ b/config/parser.go @@ -1,12 +1,14 @@ package config import ( + "bytes" _ "embed" "encoding/json" "fmt" "os" "github.com/hiddify/ray2sing/ray2sing" + SJ "github.com/sagernet/sing-box/common/json" "github.com/sagernet/sing-box/experimental/libbox" "github.com/xmdhs/clash2singbox/convert" "github.com/xmdhs/clash2singbox/model/clash" @@ -23,7 +25,8 @@ func ParseConfig(path string, debug bool) ([]byte, error) { } var jsonObj map[string]interface{} - if err := json.Unmarshal(content, &jsonObj); err == nil { + jsonDecoder := json.NewDecoder(SJ.NewCommentFilter(bytes.NewReader(content))) + if err := jsonDecoder.Decode(&jsonObj); err == nil { if jsonObj["outbounds"] == nil { return nil, fmt.Errorf("[SingboxParser] no outbounds found") }