From d2266bb52cfbc37e2cc97fcc8e00f3b8da171c14 Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Sat, 11 Jul 2020 09:24:03 +0800 Subject: [PATCH] Alias for ext: to reduce ambiguous ext: used without context --- infra/conf/router.go | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/infra/conf/router.go b/infra/conf/router.go index b3870e45..cf4879d2 100644 --- a/infra/conf/router.go +++ b/infra/conf/router.go @@ -260,9 +260,19 @@ func parseDomainRule(domain string) ([]*router.Domain, error) { } return domains, nil } - - if strings.HasPrefix(domain, "ext:") { - kv := strings.Split(domain[4:], ":") + var isExtDatFile = 0 + { + const prefix = "ext:" + if strings.HasPrefix(domain, prefix) { + isExtDatFile = len(prefix) + } + const prefixQualified = "ext-domain:" + if strings.HasPrefix(domain, prefixQualified) { + isExtDatFile = len(prefixQualified) + } + } + if isExtDatFile != 0 { + kv := strings.Split(domain[isExtDatFile:], ":") if len(kv) != 2 { return nil, newError("invalid external resource: ", domain) } @@ -314,9 +324,19 @@ func toCidrList(ips StringList) ([]*router.GeoIP, error) { }) continue } - - if strings.HasPrefix(ip, "ext:") { - kv := strings.Split(ip[4:], ":") + var isExtDatFile = 0 + { + const prefix = "ext:" + if strings.HasPrefix(ip, prefix) { + isExtDatFile = len(prefix) + } + const prefixQualified = "ext-ip:" + if strings.HasPrefix(ip, prefixQualified) { + isExtDatFile = len(prefixQualified) + } + } + if isExtDatFile != 0 { + kv := strings.Split(ip[isExtDatFile:], ":") if len(kv) != 2 { return nil, newError("invalid external resource: ", ip) }