diff --git a/docs/config.yaml b/docs/config.yaml index 6e29f1642e..669c8be7ef 100644 --- a/docs/config.yaml +++ b/docs/config.yaml @@ -942,7 +942,12 @@ rule-providers: interval: 259200 path: /path/to/save/file.yaml type: file - rule3: # mrs类型ruleset,目前仅支持domain和ipcidr,可以通过“mihomo convert-ruleset domain yaml XXX.yaml XXX.mrs”转换得到 + rule3: + # mrs类型ruleset,目前仅支持domain和ipcidr(即不支持classical), + # behavior=domain,format=yaml 可以通过“mihomo convert-ruleset domain yaml XXX.yaml XXX.mrs”转换得到 + # behavior=domain,format=text 可以通过“mihomo convert-ruleset domain text XXX.text XXX.mrs”转换得到 + # behavior=ipcidr,format=yaml 可以通过“mihomo convert-ruleset ipcidr yaml XXX.yaml XXX.mrs”转换得到 + # behavior=ipcidr,format=text 可以通过“mihomo convert-ruleset ipcidr text XXX.text XXX.mrs”转换得到 type: http url: "url" format: mrs diff --git a/rules/provider/domain_strategy.go b/rules/provider/domain_strategy.go index 462d37dcf5..a999f5bd1c 100644 --- a/rules/provider/domain_strategy.go +++ b/rules/provider/domain_strategy.go @@ -3,6 +3,7 @@ package provider import ( "errors" "io" + "strings" "github.com/metacubex/mihomo/component/trie" C "github.com/metacubex/mihomo/constant" @@ -43,6 +44,10 @@ func (d *domainStrategy) Reset() { } func (d *domainStrategy) Insert(rule string) { + if strings.ContainsRune(rule, '/') { + log.Warnln("invalid domain:[%s]", rule) + return + } err := d.domainTrie.Insert(rule, struct{}{}) if err != nil { log.Warnln("invalid domain:[%s]", rule) diff --git a/rules/provider/mrs_converter.go b/rules/provider/mrs_converter.go index c8f63fdfe8..a08301982e 100644 --- a/rules/provider/mrs_converter.go +++ b/rules/provider/mrs_converter.go @@ -2,6 +2,7 @@ package provider import ( "encoding/binary" + "errors" "io" "os" @@ -16,6 +17,9 @@ func ConvertToMrs(buf []byte, behavior P.RuleBehavior, format P.RuleFormat, w io if err != nil { return err } + if strategy.Count() == 0 { + return errors.New("empty rule") + } if _strategy, ok := strategy.(mrsRuleStrategy); ok { var encoder *zstd.Encoder encoder, err = zstd.NewWriter(w)