修复正则匹配字符串不生效的问题
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
"name": "AdGuard DNS filter",
|
||||
"url": "https://gitea.amazehome.xyz/AMAZEHOME/hosts-and-filters/raw/branch/main/filter.txt",
|
||||
"enabled": true,
|
||||
"lastUpdateTime": "2025-11-28T15:45:11.073Z"
|
||||
"lastUpdateTime": "2025-11-28T16:13:03.564Z"
|
||||
},
|
||||
{
|
||||
"name": "Adaway Default Blocklist",
|
||||
@@ -39,7 +39,7 @@
|
||||
"name": "My GitHub Rules",
|
||||
"url": "https://gitea.amazehome.xyz/AMAZEHOME/hosts-and-filters/raw/branch/main/rules/costomize.txt",
|
||||
"enabled": true,
|
||||
"lastUpdateTime": "2025-11-28T14:42:09.271Z"
|
||||
"lastUpdateTime": "2025-11-28T16:13:05.960Z"
|
||||
},
|
||||
{
|
||||
"name": "CNList",
|
||||
|
||||
@@ -374,12 +374,11 @@ func (m *ShieldManager) parseRule(line string, isLocal bool, source string) {
|
||||
}
|
||||
|
||||
case strings.HasPrefix(line, "/") && strings.HasSuffix(line, "/"):
|
||||
// 关键字匹配规则:/keyword/ 格式,不区分大小写,字面量匹配特殊字符
|
||||
keyword := strings.TrimPrefix(strings.TrimSuffix(line, "/"), "/")
|
||||
// 转义特殊字符,确保字面量匹配
|
||||
quotedKeyword := regexp.QuoteMeta(keyword)
|
||||
// 编译为不区分大小写的正则表达式,匹配域名中任意位置
|
||||
if re, err := regexp.Compile("(?i)" + quotedKeyword); err == nil {
|
||||
// 正则表达式匹配规则:/regex/ 格式,不区分大小写
|
||||
pattern := strings.TrimPrefix(strings.TrimSuffix(line, "/"), "/")
|
||||
// 编译为不区分大小写的正则表达式,确保能匹配域名中任意位置
|
||||
// 对于像 /domain/ 这样的规则,应该匹配包含 domain 字符串的任何域名
|
||||
if re, err := regexp.Compile("(?i).*" + regexp.QuoteMeta(pattern) + ".*"); err == nil {
|
||||
// 保存原始规则字符串
|
||||
m.addRegexRule(re, line, !isException, isLocal, source)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user