Skip to content

Commit 0957ab6

Browse files
committed
fix search
1 parent 1d076b1 commit 0957ab6

1 file changed

Lines changed: 14 additions & 17 deletions

File tree

geo-sni-proxy/internal/geosite/matcher.go

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,44 +131,41 @@ func parseDomainItem(s string) []*router.Domain {
131131
case strings.HasPrefix(t, "domain:"):
132132
body := strings.TrimSpace(strings.TrimPrefix(t, "domain:"))
133133
return []*router.Domain{{
134-
Type: router.Domain_Plain,
134+
Type: router.Domain_Domain,
135135
Value: strings.ToLower(body),
136136
}}
137137
case strings.HasPrefix(t, "keyword:"):
138138
body := strings.TrimSpace(strings.TrimPrefix(t, "keyword:"))
139139
return []*router.Domain{{
140140
Type: router.Domain_Plain,
141141
Value: strings.ToLower(body),
142-
Attribute: []*router.Domain_Attribute{
143-
{Key: "keyword", TypedValue: &router.Domain_Attribute_BoolValue{BoolValue: true}},
144-
},
145142
}}
146143
case strings.HasPrefix(t, "full:"):
147144
body := strings.TrimSpace(strings.TrimPrefix(t, "full:"))
148145
return []*router.Domain{{
149-
Type: router.Domain_Plain,
146+
Type: router.Domain_Full,
150147
Value: strings.ToLower(body),
151-
Attribute: []*router.Domain_Attribute{
152-
{Key: "full", TypedValue: &router.Domain_Attribute_BoolValue{BoolValue: true}},
153-
},
154148
}}
155149
case strings.HasPrefix(t, "dotless:"):
156150
body := strings.TrimSpace(strings.TrimPrefix(t, "dotless:"))
151+
value := ""
152+
switch substr := strings.ToLower(body); {
153+
case substr == "":
154+
value = "^[^.]*$"
155+
case !strings.Contains(substr, "."):
156+
value = "^[^.]*" + substr + "[^.]*$"
157+
default:
158+
return []*router.Domain{}
159+
}
157160
return []*router.Domain{{
158-
Type: router.Domain_Plain,
159-
Value: body,
160-
Attribute: []*router.Domain_Attribute{
161-
{Key: "dotless", TypedValue: &router.Domain_Attribute_BoolValue{BoolValue: true}},
162-
},
161+
Type: router.Domain_Regex,
162+
Value: value,
163163
}}
164164
default:
165165
body := strings.ToLower(t)
166166
return []*router.Domain{{
167167
Type: router.Domain_Plain,
168168
Value: body,
169-
Attribute: []*router.Domain_Attribute{
170-
{Key: "keyword", TypedValue: &router.Domain_Attribute_BoolValue{BoolValue: true}},
171-
},
172169
}}
173170
}
174171
}
@@ -195,5 +192,5 @@ func (m *Matcher) Match(domain string) bool {
195192
if m == nil || m.dm == nil {
196193
return false
197194
}
198-
return m.dm.ApplyDomain(strings.TrimSuffix(domain, "."))
195+
return m.dm.ApplyDomain(strings.ToLower(strings.TrimSuffix(domain, ".")))
199196
}

0 commit comments

Comments
 (0)