mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-07-18 08:57:58 +08:00
fix: incorrect checking of strings.Split return value
strings.Split will never return a slice of length 0 if sep is not empty, so any code that checks if the return value is of length 0 is incorrect and useless.
This commit is contained in:
@ -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)
|
||||
|
@ -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:
|
||||
|
@ -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{
|
||||
|
@ -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)
|
||||
|
@ -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{
|
||||
|
Reference in New Issue
Block a user