diff --git a/component/geodata/utils.go b/component/geodata/utils.go index 47966249..ee7946a6 100644 --- a/component/geodata/utils.go +++ b/component/geodata/utils.go @@ -1,7 +1,6 @@ package geodata import ( - "errors" "fmt" "strings" @@ -76,13 +75,13 @@ func LoadGeoSiteMatcher(countryCode string) (router.DomainMatcher, error) { if countryCode[0] == '!' { not = true countryCode = countryCode[1:] + if countryCode == "" { + return nil, fmt.Errorf("country code could not be empty") + } } countryCode = strings.ToLower(countryCode) parts := strings.Split(countryCode, "@") - if len(parts) == 0 { - return nil, errors.New("empty rule") - } listName := strings.TrimSpace(parts[0]) attrVal := parts[1:] attrs := parseAttrs(attrVal) diff --git a/config/config.go b/config/config.go index 3faca185..f5ddb971 100644 --- a/config/config.go +++ b/config/config.go @@ -1174,8 +1174,6 @@ func parseNameServer(servers []string, respectRules bool, preferH3 bool) ([]dns. for _, s := range strings.Split(u.Fragment, "&") { arr := strings.SplitN(s, "=", 2) switch len(arr) { - case 0: - continue case 1: proxyName = arr[0] case 2: diff --git a/rules/common/in_name.go b/rules/common/in_name.go index 9986d8a6..87965c70 100644 --- a/rules/common/in_name.go +++ b/rules/common/in_name.go @@ -2,8 +2,9 @@ package common import ( "fmt" - C "github.com/metacubex/mihomo/constant" "strings" + + C "github.com/metacubex/mihomo/constant" ) type InName struct { @@ -36,8 +37,12 @@ func (u *InName) Payload() string { func NewInName(iNames, adapter string) (*InName, error) { names := strings.Split(iNames, "/") - if len(names) == 0 { - return nil, fmt.Errorf("in name couldn't be empty") + for i, name := range names { + name = strings.TrimSpace(name) + if len(name) == 0 { + return nil, fmt.Errorf("in name couldn't be empty") + } + names[i] = name } return &InName{ diff --git a/rules/common/in_type.go b/rules/common/in_type.go index 0f11468f..830136e0 100644 --- a/rules/common/in_type.go +++ b/rules/common/in_type.go @@ -2,8 +2,9 @@ package common import ( "fmt" - C "github.com/metacubex/mihomo/constant" "strings" + + C "github.com/metacubex/mihomo/constant" ) type InType struct { @@ -36,8 +37,12 @@ func (u *InType) Payload() string { func NewInType(iTypes, adapter string) (*InType, error) { types := strings.Split(iTypes, "/") - if len(types) == 0 { - return nil, fmt.Errorf("in type couldn't be empty") + for i, tp := range types { + tp = strings.TrimSpace(tp) + if len(tp) == 0 { + return nil, fmt.Errorf("in type couldn't be empty") + } + types[i] = tp } tps, err := parseInTypes(types) diff --git a/rules/common/in_user.go b/rules/common/in_user.go index 6b786433..a38fdb62 100644 --- a/rules/common/in_user.go +++ b/rules/common/in_user.go @@ -2,8 +2,9 @@ package common import ( "fmt" - C "github.com/metacubex/mihomo/constant" "strings" + + C "github.com/metacubex/mihomo/constant" ) type InUser struct { @@ -36,8 +37,12 @@ func (u *InUser) Payload() string { func NewInUser(iUsers, adapter string) (*InUser, error) { users := strings.Split(iUsers, "/") - if len(users) == 0 { - return nil, fmt.Errorf("in user couldn't be empty") + for i, user := range users { + user = strings.TrimSpace(user) + if len(user) == 0 { + return nil, fmt.Errorf("in user couldn't be empty") + } + users[i] = user } return &InUser{