Skip to content

Commit 36bc780

Browse files
committed
fix patchProviders works abnormally when path is empty
1 parent e164e21 commit 36bc780

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

core/src/main/golang/native/config/fetch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func FetchAndValid(
112112
return err
113113
}
114114

115-
forEachProviders(rawCfg, func(index int, total int, name string, provider map[string]any) {
115+
forEachProviders(rawCfg, func(index int, total int, name string, provider map[string]any, prefix string) {
116116
bytes, _ := json.Marshal(&Status{
117117
Action: "FetchProviders",
118118
Args: []string{name},

core/src/main/golang/native/config/process.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"cfa/native/common"
1212

13+
"github.com/metacubex/mihomo/common/utils"
1314
"github.com/metacubex/mihomo/config"
1415
C "github.com/metacubex/mihomo/constant"
1516
"github.com/metacubex/mihomo/log"
@@ -109,10 +110,16 @@ func patchListeners(cfg *config.RawConfig, _ string) error {
109110
}
110111

111112
func patchProviders(cfg *config.RawConfig, profileDir string) error {
112-
forEachProviders(cfg, func(index int, total int, key string, provider map[string]any) {
113-
if path, ok := provider["path"].(string); ok {
114-
provider["path"] = profileDir + "/providers/" + common.ResolveAsRoot(path)
113+
forEachProviders(cfg, func(index int, total int, key string, provider map[string]any, prefix string) {
114+
path, _ := provider["path"].(string)
115+
if len(path) > 0 {
116+
path = common.ResolveAsRoot(path)
117+
} else if url, ok := provider["url"].(string); ok {
118+
path = prefix + "/" + utils.MakeHash([]byte(url)).String() // same as C.GetPathByHash
119+
} else {
120+
return // both path and url is empty, WTF???
115121
}
122+
provider["path"] = profileDir + "/providers/" + path
116123
})
117124

118125
return nil

core/src/main/golang/native/config/provider.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,23 @@ import (
66
"github.com/metacubex/mihomo/config"
77
)
88

9-
func forEachProviders(rawCfg *config.RawConfig, fun func(index int, total int, key string, provider map[string]any)) {
9+
const (
10+
PROXIES = "proxies"
11+
RULES = "rules"
12+
)
13+
14+
func forEachProviders(rawCfg *config.RawConfig, fun func(index int, total int, key string, provider map[string]any, prefix string)) {
1015
total := len(rawCfg.ProxyProvider) + len(rawCfg.RuleProvider)
1116
index := 0
1217

1318
for k, v := range rawCfg.ProxyProvider {
14-
fun(index, total, k, v)
19+
fun(index, total, k, v, PROXIES)
1520

1621
index++
1722
}
1823

1924
for k, v := range rawCfg.RuleProvider {
20-
fun(index, total, k, v)
25+
fun(index, total, k, v, RULES)
2126

2227
index++
2328
}

0 commit comments

Comments
 (0)