Files
dns-server/.trae/documents/修复屏蔽规则解析问题.md
2025-11-28 17:08:34 +08:00

34 lines
1023 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
1. **修复未定义函数问题**:移除对 `containsRegexSpecialChars` 函数的调用,该函数在代码中未定义
2. **修改正则表达式处理逻辑**
* 对于 `/` 包裹的规则,直接将中间内容作为正则表达式模式
* 不再添加 `.*` 前缀和后缀,也不再使用 `regexp.QuoteMeta` 转义
* 确保正则表达式能正确匹配域名中的相关内容
3. **修改文件**
* `/root/dns/shield/manager.go`:更新 `parseRule` 函数中的正则表达式处理逻辑
**验证修复**
确保 `/ad.qq.com/` 规则能正确匹配 `ad.qq.com` 域名
确保 `/ad/` 规则能匹配包含 `ad` 的域名
* 确保正则表达式特殊字符能被正确处理
* **测试场景**
* 测试 `/ad.qq.com/` 规则匹配 `ad.qq.com`
* 测试 `/ad.qq.com/` 规则匹配 `sub.ad.qq.com`
* 测试 `/ad/` 规则匹配 `ad.example.com`
* 测试 `/ad/` 规则匹配 `example.ad.com`
* 测试 `/^ad/` 规则匹配 `ad.example.com` 但不匹配 `example.ad.com`