diff --git a/common/matcher/domain/conf/domain.go b/common/matcher/domain/conf/domain.go index 10a8cf57..524b39bd 100644 --- a/common/matcher/domain/conf/domain.go +++ b/common/matcher/domain/conf/domain.go @@ -44,20 +44,36 @@ func ParseDomainRule(domain string) ([]*dm.Domain, error) { domainRule := new(dm.Domain) switch { case strings.HasPrefix(domain, "regexp:"): + regexpVal := domain[7:] + if len(regexpVal) == 0 { + return nil, newError("empty regexp type of rule: ", domain) + } domainRule.Type = dm.MatchingType_Regex - domainRule.Value = domain[7:] + domainRule.Value = regexpVal case strings.HasPrefix(domain, "domain:"): + domainName := domain[7:] + if len(domainName) == 0 { + return nil, newError("empty domain type of rule: ", domain) + } domainRule.Type = dm.MatchingType_Subdomain - domainRule.Value = domain[7:] + domainRule.Value = domainName case strings.HasPrefix(domain, "full:"): + fullVal := domain[5:] + if len(fullVal) == 0 { + return nil, newError("empty full domain type of rule: ", domain) + } domainRule.Type = dm.MatchingType_Full - domainRule.Value = domain[5:] + domainRule.Value = fullVal case strings.HasPrefix(domain, "keyword:"): + keywordVal := domain[8:] + if len(keywordVal) == 0 { + return nil, newError("empty keyword type of rule: ", domain) + } domainRule.Type = dm.MatchingType_Keyword - domainRule.Value = domain[8:] + domainRule.Value = keywordVal case strings.HasPrefix(domain, "dotless:"): domainRule.Type = dm.MatchingType_Regex diff --git a/common/matcher/geosite/attribute.go b/common/matcher/geosite/attribute.go index a16361c1..c2fc0b30 100644 --- a/common/matcher/geosite/attribute.go +++ b/common/matcher/geosite/attribute.go @@ -1,5 +1,7 @@ package geosite +import "strings" + type AttributeList struct { matcher []AttributeMatcher } @@ -25,7 +27,7 @@ type BooleanMatcher string func (m BooleanMatcher) Match(domain *Domain) bool { for _, attr := range domain.Attribute { - if attr.Key == string(m) { + if strings.EqualFold(attr.GetKey(), string(m)) { return true } } diff --git a/infra/conf/router.go b/infra/conf/router.go index 1e005bf2..e905b672 100644 --- a/infra/conf/router.go +++ b/infra/conf/router.go @@ -261,21 +261,21 @@ func ParseRule(msg json.RawMessage) (*router.RoutingRule, error) { if err != nil { return nil, newError("invalid router rule").Base(err) } - if rawRule.Type == "field" { + if strings.EqualFold(rawRule.Type, "field") { fieldrule, err := parseFieldRule(msg) if err != nil { return nil, newError("invalid field rule").Base(err) } return fieldrule, nil } - if rawRule.Type == "chinaip" { + if strings.EqualFold(rawRule.Type, "chinaip") { chinaiprule, err := parseChinaIPRule(msg) if err != nil { return nil, newError("invalid chinaip rule").Base(err) } return chinaiprule, nil } - if rawRule.Type == "chinasites" { + if strings.EqualFold(rawRule.Type, "chinasites") { chinasitesrule, err := parseChinaSitesRule(msg) if err != nil { return nil, newError("invalid chinasites rule").Base(err)