mirror of
https://github.com/SagerNet/sing-geosite.git
synced 2026-07-06 11:38:40 +08:00
Avoid merging category-companies@cn into geolocation-cn.
Keep company-wide @cn buckets like google@cn out of the generic mainland direct list so generated geolocation-cn does not classify blocked Google service domains as direct-connect targets. Made-with: Cursor
This commit is contained in:
parent
dd64ae0ebf
commit
b0cc8dca91
10
main.go
10
main.go
@ -246,6 +246,13 @@ func mergeTags(data map[string][]geosite.Item) {
|
|||||||
codeList = append(codeList, code)
|
codeList = append(codeList, code)
|
||||||
}
|
}
|
||||||
var cnCodeList []string
|
var cnCodeList []string
|
||||||
|
// Company-wide @cn buckets may contain domains that are still unsuitable for
|
||||||
|
// a generic mainland-direct list. For example, category-companies@cn pulls in
|
||||||
|
// google@cn entries such as ssl.gstatic.com and fonts.googleapis.com, which
|
||||||
|
// makes geolocation-cn too broad for common direct-routing use.
|
||||||
|
geolocationCNMergeExclusions := map[string]bool{
|
||||||
|
"category-companies@cn": true,
|
||||||
|
}
|
||||||
for _, code := range codeList {
|
for _, code := range codeList {
|
||||||
codeParts := strings.Split(code, "@")
|
codeParts := strings.Split(code, "@")
|
||||||
if len(codeParts) != 2 {
|
if len(codeParts) != 2 {
|
||||||
@ -260,6 +267,9 @@ func mergeTags(data map[string][]geosite.Item) {
|
|||||||
if strings.HasSuffix(codeParts[0], "-cn") || strings.HasSuffix(codeParts[0], "-!cn") {
|
if strings.HasSuffix(codeParts[0], "-cn") || strings.HasSuffix(codeParts[0], "-!cn") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if geolocationCNMergeExclusions[code] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
cnCodeList = append(cnCodeList, code)
|
cnCodeList = append(cnCodeList, code)
|
||||||
}
|
}
|
||||||
for _, code := range codeList {
|
for _, code := range codeList {
|
||||||
|
|||||||
41
main_test.go
Normal file
41
main_test.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/sagernet/sing-box/common/geosite"
|
||||||
|
)
|
||||||
|
|
||||||
|
func hasItem(items []geosite.Item, want geosite.Item) bool {
|
||||||
|
for _, item := range items {
|
||||||
|
if item == want {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMergeTagsSkipsCategoryCompaniesAtCN(t *testing.T) {
|
||||||
|
companyItem := geosite.Item{Type: geosite.RuleTypeDomain, Value: "ssl.gstatic.com"}
|
||||||
|
devItem := geosite.Item{Type: geosite.RuleTypeDomain, Value: "pkg.go.dev"}
|
||||||
|
baseItem := geosite.Item{Type: geosite.RuleTypeDomain, Value: "example.cn"}
|
||||||
|
|
||||||
|
data := map[string][]geosite.Item{
|
||||||
|
"geolocation-cn": {baseItem},
|
||||||
|
"category-companies@cn": {companyItem},
|
||||||
|
"category-dev@cn": {devItem},
|
||||||
|
}
|
||||||
|
|
||||||
|
mergeTags(data)
|
||||||
|
|
||||||
|
got := data["geolocation-cn"]
|
||||||
|
if !hasItem(got, baseItem) {
|
||||||
|
t.Fatalf("base geolocation-cn item missing after merge")
|
||||||
|
}
|
||||||
|
if !hasItem(got, devItem) {
|
||||||
|
t.Fatalf("expected category-dev@cn item to still merge into geolocation-cn")
|
||||||
|
}
|
||||||
|
if hasItem(got, companyItem) {
|
||||||
|
t.Fatalf("did not expect category-companies@cn item to merge into geolocation-cn")
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user