Skip to content

Commit a97f238

Browse files
NkBeNkBe
authored andcommitted
fix: handle custom action in rule config
修正當自定義配置中包含 action(如 sniff, resolve)時,自動將 outbound 設為 null,避免同時存在 action 和 outbound 欄位導致配置衝突
1 parent c94b59e commit a97f238

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

app/src/main/java/io/nekohasekai/sagernet/fmt/ConfigBuilder.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,27 @@ fun buildConfig(
610610
if (ruleObj.outbound == TAG_BLOCK) {
611611
ruleObj.outbound = null
612612
ruleObj.action = "reject"
613+
} else {
614+
// 檢查使用者自定義配置是否包含 "action"
615+
var hasCustomAction = false
616+
if (!rule.config.isNullOrBlank()) {
617+
try {
618+
// 僅解析為通用 Map 來檢查 "action" 鍵的存在
619+
@Suppress("UNCHECKED_CAST")
620+
val customMap = gson.fromJson(rule.config, Map::class.java) as? Map<String, Any>
621+
if (customMap?.containsKey("action") == true) {
622+
hasCustomAction = true
623+
}
624+
} catch (e: Exception) {
625+
// JSON 解析失敗或格式不符,忽略
626+
}
627+
}
628+
629+
if (hasCustomAction) {
630+
// 如果有自定義 action (如 sniff, resolve),
631+
// 則不應有 outbound 欄位,將其設為 null
632+
ruleObj.outbound = null
633+
}
613634
}
614635
route.rules.add(ruleObj)
615636
route.rule_set.addAll(ruleSets)

0 commit comments

Comments
 (0)