Fix json parser for files with comment

This commit is contained in:
problematicconsumer
2024-01-19 22:19:53 +03:30
parent bb006e10d3
commit eb2d364fcf

View File

@@ -1,12 +1,14 @@
package config package config
import ( import (
"bytes"
_ "embed" _ "embed"
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
"github.com/hiddify/ray2sing/ray2sing" "github.com/hiddify/ray2sing/ray2sing"
SJ "github.com/sagernet/sing-box/common/json"
"github.com/sagernet/sing-box/experimental/libbox" "github.com/sagernet/sing-box/experimental/libbox"
"github.com/xmdhs/clash2singbox/convert" "github.com/xmdhs/clash2singbox/convert"
"github.com/xmdhs/clash2singbox/model/clash" "github.com/xmdhs/clash2singbox/model/clash"
@@ -23,7 +25,8 @@ func ParseConfig(path string, debug bool) ([]byte, error) {
} }
var jsonObj map[string]interface{} 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 { if jsonObj["outbounds"] == nil {
return nil, fmt.Errorf("[SingboxParser] no outbounds found") return nil, fmt.Errorf("[SingboxParser] no outbounds found")
} }