Skip to content

Commit

Permalink
Fix json parser for files with comment
Browse files Browse the repository at this point in the history
  • Loading branch information
0xConsumer committed Jan 19, 2024
1 parent bb006e1 commit eb2d364
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion config/parser.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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")
}
Expand Down

0 comments on commit eb2d364

Please sign in to comment.