feat: add filename blacklist filtering for search index#262
feat: add filename blacklist filtering for search index#262Johnson-zs wants to merge 1 commit intolinuxdeepin:masterfrom
Conversation
Added filename blacklist matching functionality to exclude blacklisted paths from search index directory checks. This prevents indexing of sensitive or system directories that should not be included in search results. The implementation includes: 1. Integration of BlacklistMatcher utility in search index directory validation 2. Comprehensive test cases for blacklist matching logic 3. Support for both absolute path matching and directory name pattern matching 4. Edge case handling to prevent false positives Log: Added filename blacklist filtering to exclude sensitive directories from search indexing Influence: 1. Test search functionality with paths that should be blacklisted 2. Verify that blacklisted directories do not appear in search results 3. Test edge cases like similar directory names that should not match 4. Validate that non-blacklisted paths are still indexed correctly 5. Check search performance with blacklist filtering enabled feat: 为搜索索引添加文件名黑名单过滤功能 在搜索索引目录检查中添加了文件名黑名单匹配功能,排除黑名单中的路径不被索 引。这可以防止敏感或系统目录被包含在搜索结果中。 实现包括: 1. 在搜索索引目录验证中集成黑名单匹配工具 2. 黑名单匹配逻辑的全面测试用例 3. 支持绝对路径匹配和目录名模式匹配 4. 防止误报的边缘情况处理 Log: 新增文件名黑名单过滤功能,排除敏感目录不被搜索索引 Influence: 1. 测试应被黑名单排除的路径的搜索功能 2. 验证黑名单目录不会出现在搜索结果中 3. 测试边缘情况,如不应匹配的相似目录名 4. 确认非黑名单路径仍能正确被索引 5. 检查启用黑名单过滤后的搜索性能
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Johnson-zs The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
deepin pr auto review这段代码实现了一个文件名黑名单匹配功能,用于判断特定路径是否在黑名单中。以下是对代码的详细审查和改进建议: 1. 语法与逻辑优点:
问题与建议:
2. 代码质量优点:
问题与建议:
3. 代码性能问题与建议:
4. 代码安全问题与建议:
5. 其他建议
改进后的代码示例以下是改进后的 #include "filenameblacklistmatcher.h"
#include <QDir>
#include <QSet>
DFM_SEARCH_BEGIN_NS
namespace Global {
namespace BlacklistMatcher {
namespace {
QString normalizePathForBlacklistMatch(const QString &path) {
return QDir::cleanPath(path.trimmed());
}
bool isAbsolutePathMatch(const QString &normalizedPath, const QString &blacklistAbsolutePath) {
const QString normalizedRulePath = normalizePathForBlacklistMatch(blacklistAbsolutePath);
if (normalizedRulePath.isEmpty()) {
return false;
}
if (normalizedRulePath == "/") {
return normalizedPath.startsWith('/');
}
return normalizedPath == normalizedRulePath || normalizedPath.startsWith(normalizedRulePath + '/');
}
}
bool isPathBlacklisted(const QString &inputPath, const QStringList &blacklistEntries) {
if (inputPath.isEmpty()) {
return false;
}
const QString normalizedPath = normalizePathForBlacklistMatch(inputPath);
const QStringList pathSegments = normalizedPath.split('/', Qt::SkipEmptyParts);
const QSet<QString> pathSegmentSet(pathSegments.begin(), pathSegments.end());
for (const QString &entry : blacklistEntries) {
const QString trimmedEntry = entry.trimmed();
if (trimmedEntry.isEmpty()) {
continue;
}
if (QDir::isAbsolutePath(trimmedEntry)) {
if (isAbsolutePathMatch(normalizedPath, trimmedEntry)) {
return true;
}
} else {
if (pathSegmentSet.contains(trimmedEntry)) {
return true;
}
}
}
return false;
}
} // namespace BlacklistMatcher
} // namespace Global
DFM_SEARCH_END_NS总结这段代码整体质量较高,但在测试代码分离、性能优化和注释方面有改进空间。建议将测试代码移到单独的文件中,并使用 |
Added filename blacklist matching functionality to exclude blacklisted paths from search index directory checks. This prevents indexing of sensitive or system directories that should not be included in search results.
The implementation includes:
Log: Added filename blacklist filtering to exclude sensitive directories from search indexing
Influence:
feat: 为搜索索引添加文件名黑名单过滤功能
在搜索索引目录检查中添加了文件名黑名单匹配功能,排除黑名单中的路径不被索
引。这可以防止敏感或系统目录被包含在搜索结果中。
实现包括:
Log: 新增文件名黑名单过滤功能,排除敏感目录不被搜索索引
Influence: