Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ SearchError FileNameSearchEngine::validateSearchConditions()
}

// 文件名搜索特定验证
if (m_currentQuery.type() == SearchQuery::Type::Simple ||
m_currentQuery.type() == SearchQuery::Type::Wildcard) {
if (m_currentQuery.type() == SearchQuery::Type::Simple
|| m_currentQuery.type() == SearchQuery::Type::Wildcard) {
// 允许对一个类型, 后缀进行搜索,获取类型下所有文件
if (m_currentQuery.keyword().isEmpty() && fileTypes.isEmpty() && fileExts.isEmpty()) {
return SearchError(FileNameSearchErrorCode::KeywordIsEmpty);
}

// pinyin (wildcard类型不支持拼音搜索)
if (m_currentQuery.type() == SearchQuery::Type::Simple &&
api.pinyinEnabled() && !Global::isPinyinSequence(m_currentQuery.keyword())) {
if (m_currentQuery.type() == SearchQuery::Type::Simple
&& api.pinyinEnabled() && !Global::isPinyinSequence(m_currentQuery.keyword())) {
qWarning() << SearchError(FileNameSearchErrorCode::InvalidPinyinFormat).message() << "key: " << m_currentQuery.keyword();
}
}
Expand Down
51 changes: 26 additions & 25 deletions src/dfm-search/dfm-search-lib/utils/searchutility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,13 @@
if (input.isEmpty())
return false;

// 清洗输入:移除所有非字母字符,只保留字母用于拼音检验
QString cleanedInput = input;
cleanedInput.remove(QRegularExpression("[^a-zA-Z]"));

if (cleanedInput.isEmpty())
return false;

// 合法的拼音音节表(预先定义所有可能的拼音音节组合)
static const QSet<QString> validSyllables = {
// 单韵母音节 - 只有 a, o, e 可以单独成音节
Expand Down Expand Up @@ -383,18 +390,18 @@
};

// 特殊处理规则:单个字母'i', 'u', 'v', 'ü'不能单独成音节
if (input.length() == 1) {
QChar ch = input.toLower()[0];
if (cleanedInput.length() == 1) {
QChar ch = cleanedInput.toLower()[0];
if (ch == 'i' || ch == 'u' || ch == 'v' || ch == QChar(0x00FC)) // 0x00FC是ü的Unicode编码
return false;
}

// 特殊处理规则:检查重复字母如'vvv'
if (input.length() >= 3) {
if (cleanedInput.length() >= 3) {
bool allSame = true;
QChar firstChar = input.toLower()[0];
for (int i = 1; i < input.length(); i++) {
if (input.toLower()[i] != firstChar) {
QChar firstChar = cleanedInput.toLower()[0];
for (int i = 1; i < cleanedInput.length(); i++) {
if (cleanedInput.toLower()[i] != firstChar) {
allSame = false;
break;
}
Expand All @@ -403,7 +410,7 @@
return false;
}

QString str = input.toLower();
QString str = cleanedInput.toLower();
str.replace("ü", "v"); // 统一处理 ü

// 尝试所有可能的分割方式
Expand All @@ -415,38 +422,32 @@
if (input.isEmpty())
return false;

// 拼音首字母的验证规则:
// 1. 必须包含至少一个英文字母(大小写)
// 2. 可以包含数字和英文符号
// 3. 长度在1-255之间(合理的文件名长度)

QString str = input.trimmed();

// 长度检查
if (str.length() == 0 || str.length() > 255)
return false;

// 必须包含至少一个英文字母
// 核心验证:
// 1. 必须包含至少一个英文字母
// 2. 不能包含中文字符
// 3. 允许数字、符号等其他任意字符

bool hasLetter = false;
for (const QChar &ch : str) {
if (ch.isLetter()) {
// 检查是否为中文(拼音缩写不应包含中文)
if (ch.script() == QChar::Script_Han)
return false;

// 检查是否为英文字母(拉丁字母)
if (ch.isLetter() && ch.script() == QChar::Script_Latin)
hasLetter = true;
break;
}
}

if (!hasLetter)
return false;

// 字符检查:允许字母、数字和常见符号
QRegularExpression validCharsRegex("^[a-zA-Z0-9._-]+$");
if (!validCharsRegex.match(str).hasMatch())
return false;

return true;
return hasLetter;
}

bool isHiddenPathOrInHiddenDir(const QString &absolutePath)

Check warning on line 450 in src/dfm-search/dfm-search-lib/utils/searchutility.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'isHiddenPathOrInHiddenDir' is never used.

Check warning on line 450 in src/dfm-search/dfm-search-lib/utils/searchutility.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

The function 'isHiddenPathOrInHiddenDir' is never used.
{
int start = 0;
int len = absolutePath.length();
Expand Down
Loading