From 356c10fc54a3196e628ec867e1bf374c1c074f6e Mon Sep 17 00:00:00 2001 From: Zhang Sheng Date: Mon, 26 Jan 2026 16:28:36 +0800 Subject: [PATCH 1/2] fix: improve pinyin validation logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enhanced pinyin sequence validation by adding input sanitization to remove non-alphabetic characters before checking. This prevents false positives when users input pinyin with numbers or special characters mixed in. The validation now focuses only on alphabetic content for accurate pinyin detection. The changes include: 1. Added input cleaning to remove non-letter characters 2. Added early return for empty cleaned input 3. Updated all validation logic to use cleaned input 4. Maintained existing pinyin syllable validation rules Log: Improved pinyin input validation to handle mixed content better Influence: 1. Test pinyin input with numbers (e.g., "zhang123san") 2. Test pinyin input with special characters (e.g., "zhang-san") 3. Verify pure pinyin sequences still work correctly 4. Test edge cases like single invalid letters 5. Verify mixed Chinese-pinyin inputs are handled properly fix: 改进拼音验证逻辑 增强拼音序列验证功能,在检查前添加输入清洗步骤以移除非字母字符。这可以防 止用户输入包含数字或特殊字符的拼音时出现误判。验证现在只关注字母内容以实 现准确的拼音检测。 变更包括: 1. 添加输入清洗功能以移除非字母字符 2. 为空清洗输入添加提前返回 3. 更新所有验证逻辑使用清洗后的输入 4. 保持现有的拼音音节验证规则 Log: 改进拼音输入验证以更好地处理混合内容 Influence: 1. 测试包含数字的拼音输入(如"zhang123san") 2. 测试包含特殊字符的拼音输入(如"zhang-san") 3. 验证纯拼音序列仍能正常工作 4. 测试边缘情况如单个无效字母 5. 验证混合中英文拼音输入的正确处理 --- .../filenamesearch/filenamesearchengine.cpp | 8 +++---- .../dfm-search-lib/utils/searchutility.cpp | 21 ++++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/dfm-search/dfm-search-lib/filenamesearch/filenamesearchengine.cpp b/src/dfm-search/dfm-search-lib/filenamesearch/filenamesearchengine.cpp index 4675db9..57373ea 100644 --- a/src/dfm-search/dfm-search-lib/filenamesearch/filenamesearchengine.cpp +++ b/src/dfm-search/dfm-search-lib/filenamesearch/filenamesearchengine.cpp @@ -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(); } } diff --git a/src/dfm-search/dfm-search-lib/utils/searchutility.cpp b/src/dfm-search/dfm-search-lib/utils/searchutility.cpp index 4de958e..4ef0f48 100644 --- a/src/dfm-search/dfm-search-lib/utils/searchutility.cpp +++ b/src/dfm-search/dfm-search-lib/utils/searchutility.cpp @@ -330,6 +330,13 @@ bool isPinyinSequence(const QString &input) if (input.isEmpty()) return false; + // 清洗输入:移除所有非字母字符,只保留字母用于拼音检验 + QString cleanedInput = input; + cleanedInput.remove(QRegularExpression("[^a-zA-Z]")); + + if (cleanedInput.isEmpty()) + return false; + // 合法的拼音音节表(预先定义所有可能的拼音音节组合) static const QSet validSyllables = { // 单韵母音节 - 只有 a, o, e 可以单独成音节 @@ -383,18 +390,18 @@ bool isPinyinSequence(const QString &input) }; // 特殊处理规则:单个字母'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; } @@ -403,7 +410,7 @@ bool isPinyinSequence(const QString &input) return false; } - QString str = input.toLower(); + QString str = cleanedInput.toLower(); str.replace("ü", "v"); // 统一处理 ü // 尝试所有可能的分割方式 From c1505239f4abfeae33db5e41bf616abff16a2cc9 Mon Sep 17 00:00:00 2001 From: Zhang Sheng Date: Mon, 26 Jan 2026 16:54:38 +0800 Subject: [PATCH 2/2] fix: remove unnecessary regex check in pinyin acronym detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The regex validation that restricted input to only letters, numbers, and common symbols has been removed from the pinyin acronym sequence detection function. This check was overly restrictive and prevented legitimate pinyin acronyms containing other characters from being properly recognized. The core logic for detecting pinyin sequences remains intact, including the essential letter presence check. Log: Improved pinyin acronym recognition by removing character restrictions Influence: 1. Test pinyin acronym detection with various special characters 2. Verify that Chinese pinyin sequences with mixed characters are now recognized 3. Confirm that basic pinyin detection still works correctly 4. Test edge cases with symbols that were previously blocked fix: 移除拼音首字母检测中的不必要正则检查 从拼音首字母序列检测函数中移除了限制输入只能包含字母、数字和常见符号的正 则验证。此检查过于严格,阻止了包含其他字符的合法拼音首字母被正确识别。拼 音序列检测的核心逻辑保持完整,包括必要的字母存在检查。 Log: 通过移除字符限制改进了拼音首字母识别 Influence: 1. 测试包含各种特殊字符的拼音首字母检测 2. 验证包含混合字符的中文拼音序列现在能被识别 3. 确认基本的拼音检测功能仍然正常工作 4. 测试之前被阻止的符号边界情况 Bug: https://pms.uniontech.com/bug-view-339101.html --- .../dfm-search-lib/utils/searchutility.cpp | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/dfm-search/dfm-search-lib/utils/searchutility.cpp b/src/dfm-search/dfm-search-lib/utils/searchutility.cpp index 4ef0f48..4c106a0 100644 --- a/src/dfm-search/dfm-search-lib/utils/searchutility.cpp +++ b/src/dfm-search/dfm-search-lib/utils/searchutility.cpp @@ -422,35 +422,29 @@ bool isPinyinAcronymSequence(const QString &input) 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)