mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-02-26 16:57:08 +00: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:
@@ -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