mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-07-18 17:08:06 +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
|
package geodata
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -76,13 +75,13 @@ func LoadGeoSiteMatcher(countryCode string) (router.DomainMatcher, error) {
|
|||||||
if countryCode[0] == '!' {
|
if countryCode[0] == '!' {
|
||||||
not = true
|
not = true
|
||||||
countryCode = countryCode[1:]
|
countryCode = countryCode[1:]
|
||||||
|
if countryCode == "" {
|
||||||
|
return nil, fmt.Errorf("country code could not be empty")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
countryCode = strings.ToLower(countryCode)
|
countryCode = strings.ToLower(countryCode)
|
||||||
|
|
||||||
parts := strings.Split(countryCode, "@")
|
parts := strings.Split(countryCode, "@")
|
||||||
if len(parts) == 0 {
|
|
||||||
return nil, errors.New("empty rule")
|
|
||||||
}
|
|
||||||
listName := strings.TrimSpace(parts[0])
|
listName := strings.TrimSpace(parts[0])
|
||||||
attrVal := parts[1:]
|
attrVal := parts[1:]
|
||||||
attrs := parseAttrs(attrVal)
|
attrs := parseAttrs(attrVal)
|
||||||
|
@ -1174,8 +1174,6 @@ func parseNameServer(servers []string, respectRules bool, preferH3 bool) ([]dns.
|
|||||||
for _, s := range strings.Split(u.Fragment, "&") {
|
for _, s := range strings.Split(u.Fragment, "&") {
|
||||||
arr := strings.SplitN(s, "=", 2)
|
arr := strings.SplitN(s, "=", 2)
|
||||||
switch len(arr) {
|
switch len(arr) {
|
||||||
case 0:
|
|
||||||
continue
|
|
||||||
case 1:
|
case 1:
|
||||||
proxyName = arr[0]
|
proxyName = arr[0]
|
||||||
case 2:
|
case 2:
|
||||||
|
@ -2,8 +2,9 @@ package common
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
C "github.com/metacubex/mihomo/constant"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
C "github.com/metacubex/mihomo/constant"
|
||||||
)
|
)
|
||||||
|
|
||||||
type InName struct {
|
type InName struct {
|
||||||
@ -36,8 +37,12 @@ func (u *InName) Payload() string {
|
|||||||
|
|
||||||
func NewInName(iNames, adapter string) (*InName, error) {
|
func NewInName(iNames, adapter string) (*InName, error) {
|
||||||
names := strings.Split(iNames, "/")
|
names := strings.Split(iNames, "/")
|
||||||
if len(names) == 0 {
|
for i, name := range names {
|
||||||
return nil, fmt.Errorf("in name couldn't be empty")
|
name = strings.TrimSpace(name)
|
||||||
|
if len(name) == 0 {
|
||||||
|
return nil, fmt.Errorf("in name couldn't be empty")
|
||||||
|
}
|
||||||
|
names[i] = name
|
||||||
}
|
}
|
||||||
|
|
||||||
return &InName{
|
return &InName{
|
||||||
|
@ -2,8 +2,9 @@ package common
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
C "github.com/metacubex/mihomo/constant"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
C "github.com/metacubex/mihomo/constant"
|
||||||
)
|
)
|
||||||
|
|
||||||
type InType struct {
|
type InType struct {
|
||||||
@ -36,8 +37,12 @@ func (u *InType) Payload() string {
|
|||||||
|
|
||||||
func NewInType(iTypes, adapter string) (*InType, error) {
|
func NewInType(iTypes, adapter string) (*InType, error) {
|
||||||
types := strings.Split(iTypes, "/")
|
types := strings.Split(iTypes, "/")
|
||||||
if len(types) == 0 {
|
for i, tp := range types {
|
||||||
return nil, fmt.Errorf("in type couldn't be empty")
|
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)
|
tps, err := parseInTypes(types)
|
||||||
|
@ -2,8 +2,9 @@ package common
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
C "github.com/metacubex/mihomo/constant"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
C "github.com/metacubex/mihomo/constant"
|
||||||
)
|
)
|
||||||
|
|
||||||
type InUser struct {
|
type InUser struct {
|
||||||
@ -36,8 +37,12 @@ func (u *InUser) Payload() string {
|
|||||||
|
|
||||||
func NewInUser(iUsers, adapter string) (*InUser, error) {
|
func NewInUser(iUsers, adapter string) (*InUser, error) {
|
||||||
users := strings.Split(iUsers, "/")
|
users := strings.Split(iUsers, "/")
|
||||||
if len(users) == 0 {
|
for i, user := range users {
|
||||||
return nil, fmt.Errorf("in user couldn't be empty")
|
user = strings.TrimSpace(user)
|
||||||
|
if len(user) == 0 {
|
||||||
|
return nil, fmt.Errorf("in user couldn't be empty")
|
||||||
|
}
|
||||||
|
users[i] = user
|
||||||
}
|
}
|
||||||
|
|
||||||
return &InUser{
|
return &InUser{
|
||||||
|
Reference in New Issue
Block a user