Skip to content

Commit 1db3e45

Browse files
committed
chore: better converter
1 parent 4f8a5a5 commit 1db3e45

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

docs/config.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,12 @@ rule-providers:
942942
interval: 259200
943943
path: /path/to/save/file.yaml
944944
type: file
945-
rule3: # mrs类型ruleset,目前仅支持domain和ipcidr,可以通过“mihomo convert-ruleset domain yaml XXX.yaml XXX.mrs”转换得到
945+
rule3:
946+
# mrs类型ruleset,目前仅支持domain和ipcidr(即不支持classical),
947+
# behavior=domain,format=yaml 可以通过“mihomo convert-ruleset domain yaml XXX.yaml XXX.mrs”转换得到
948+
# behavior=domain,format=text 可以通过“mihomo convert-ruleset domain text XXX.text XXX.mrs”转换得到
949+
# behavior=ipcidr,format=yaml 可以通过“mihomo convert-ruleset ipcidr yaml XXX.yaml XXX.mrs”转换得到
950+
# behavior=ipcidr,format=text 可以通过“mihomo convert-ruleset ipcidr text XXX.text XXX.mrs”转换得到
946951
type: http
947952
url: "url"
948953
format: mrs

rules/provider/domain_strategy.go

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package provider
33
import (
44
"errors"
55
"io"
6+
"strings"
67

78
"github.com/metacubex/mihomo/component/trie"
89
C "github.com/metacubex/mihomo/constant"
@@ -43,6 +44,10 @@ func (d *domainStrategy) Reset() {
4344
}
4445

4546
func (d *domainStrategy) Insert(rule string) {
47+
if strings.ContainsRune(rule, '/') {
48+
log.Warnln("invalid domain:[%s]", rule)
49+
return
50+
}
4651
err := d.domainTrie.Insert(rule, struct{}{})
4752
if err != nil {
4853
log.Warnln("invalid domain:[%s]", rule)

rules/provider/mrs_converter.go

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package provider
22

33
import (
44
"encoding/binary"
5+
"errors"
56
"io"
67
"os"
78

@@ -16,6 +17,9 @@ func ConvertToMrs(buf []byte, behavior P.RuleBehavior, format P.RuleFormat, w io
1617
if err != nil {
1718
return err
1819
}
20+
if strategy.Count() == 0 {
21+
return errors.New("empty rule")
22+
}
1923
if _strategy, ok := strategy.(mrsRuleStrategy); ok {
2024
var encoder *zstd.Encoder
2125
encoder, err = zstd.NewWriter(w)

0 commit comments

Comments
 (0)