Skip to content

fix: correct loading of string list from DConfig#316

Merged
Johnson-zs merged 1 commit into
linuxdeepin:semantic-searchfrom
Kakueeen:semantic-search
Jun 23, 2026
Merged

fix: correct loading of string list from DConfig#316
Johnson-zs merged 1 commit into
linuxdeepin:semantic-searchfrom
Kakueeen:semantic-search

Conversation

@Kakueeen

Copy link
Copy Markdown
Contributor
  1. Changed value.toStringList() to value.toString().split(';') in
    tryLoadStringListFromDConfigInternal.
  2. The DConfig value for supportedFileExtensions is stored as a
    semicolon-separated string, not a native QStringList.
  3. Previously, toStringList() would fail due to type mismatch,
    returning std::nullopt or an empty list.
  4. Now the function correctly parses the string into a list, restoring
    proper file extension filtering in searches.

Log: Fixed search file extension configuration loading

Influence:

  1. Verify that searching with file extension filters (e.g., *.txt,
    *.pdf) functions correctly.
  2. Test with multiple extensions in the configuration string.
  3. Test with an empty string to ensure no extensions are applied.
  4. Test with invalid or malformed extension strings (e.g., missing
    separators).
  5. Verify that the fix does not break existing functionality when the
    config is not set.

fix: 修正从 DConfig 加载字符串列表的方式

  1. tryLoadStringListFromDConfigInternal 中的 value.toStringList()
    改为 value.toString().split(';')
  2. supportedFileExtensions 的 DConfig 值存储为分号分隔的字符串,而非原
    生的 QStringList。
  3. 之前使用 toStringList() 会因类型不匹配而返回 std::nullopt 或空
    列表。
  4. 现在函数能正确解析字符串为列表,恢复搜索中正确的文件扩展名过滤。

Log: 修复搜索文件扩展名配置加载问题

Influence:

  1. 验证带文件扩展名过滤(如 *.txt, *.pdf)的搜索功能是否正常。
  2. 测试配置中包含多个扩展名的情况。
  3. 测试空字符串配置,确保不应用任何扩展名过滤。
  4. 测试无效或格式错误的扩展名字符串(例如缺少分隔符)。
  5. 验证未设置配置时原有功能不受影响。

1. Changed `value.toStringList()` to `value.toString().split(';')` in
`tryLoadStringListFromDConfigInternal`.
2. The DConfig value for `supportedFileExtensions` is stored as a
semicolon-separated string, not a native QStringList.
3. Previously, `toStringList()` would fail due to type mismatch,
returning `std::nullopt` or an empty list.
4. Now the function correctly parses the string into a list, restoring
proper file extension filtering in searches.

Log: Fixed search file extension configuration loading

Influence:
1. Verify that searching with file extension filters (e.g., *.txt,
*.pdf) functions correctly.
2. Test with multiple extensions in the configuration string.
3. Test with an empty string to ensure no extensions are applied.
4. Test with invalid or malformed extension strings (e.g., missing
separators).
5. Verify that the fix does not break existing functionality when the
config is not set.

fix: 修正从 DConfig 加载字符串列表的方式

1. 将 `tryLoadStringListFromDConfigInternal` 中的 `value.toStringList()`
改为 `value.toString().split(';')`。
2. `supportedFileExtensions` 的 DConfig 值存储为分号分隔的字符串,而非原
生的 QStringList。
3. 之前使用 `toStringList()` 会因类型不匹配而返回 `std::nullopt` 或空
列表。
4. 现在函数能正确解析字符串为列表,恢复搜索中正确的文件扩展名过滤。

Log: 修复搜索文件扩展名配置加载问题

Influence:
1. 验证带文件扩展名过滤(如 *.txt, *.pdf)的搜索功能是否正常。
2. 测试配置中包含多个扩展名的情况。
3. 测试空字符串配置,确保不应用任何扩展名过滤。
4. 测试无效或格式错误的扩展名字符串(例如缺少分隔符)。
5. 验证未设置配置时原有功能不受影响。

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @Kakueeen, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码修复了DConfig配置读取时的类型不匹配问题,逻辑正确且无明显缺陷
语法逻辑完全正确,代码质量良好,性能高效,无安全漏洞,扣除5分因为硬编码分隔符及未过滤空串

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

修改后的代码通过先调用toString()将QVariant转换为QString,再调用split(';')切割为QStringList,完美解决了原代码因后端返回单字符串导致toStringList()类型不匹配返回std::nullopt的问题,返回值类型与函数签名std::optional严格匹配。
潜在问题:当配置项字符串以分号结尾或包含连续分号(如"txt;doc;")时,split会产生空的QString元素,可能影响后续扩展名遍历匹配逻辑。
建议:使用QString::split的Qt::SkipEmptyParts参数过滤空串,如value.toString().split(';', Qt::SkipEmptyParts)。

  • 2.代码质量(良好)✓

代码变更精简直接,准确针对BUG描述中的核心报错进行修复,没有引入多余的复杂逻辑或冗余代码。
潜在问题:分号';'作为分隔符被硬编码在业务逻辑中,如果后端配置格式未来发生变更,维护成本略高。
建议:可将分隔符提取为静态常量或在函数头部添加明确注释说明后端数据格式约束。

  • 3.代码性能(高效)✓

toString()与split()均为Qt基础字符串操作,时间复杂度为O(N),对于系统配置项这种极短长度的字符串来说,内存分配与性能开销可以忽略不计。
建议:保持现状即可。

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码仅涉及本地DConfig配置字符串的拆分操作,不涉及外部不可信输入、命令拼接、内存越界或权限校验,不存在安全风险。

  • 建议:保持现有的安全基线,确保下游使用该QStringList进行文件扩展名匹配时,做好路径规范化处理以防潜在的路径遍历风险。

■ 【改进建议代码示例】

diff --git a/src/dfm-search/dfm-search-lib/utils/searchutility.cpp b/src/dfm-search/dfm-search-lib/utils/searchutility.cpp
index 199b81b..303e6bc 100644
--- a/src/dfm-search/dfm-search-lib/utils/searchutility.cpp
+++ b/src/dfm-search/dfm-search-lib/utils/searchutility.cpp
@@ -129,7 +129,7 @@ static std::optional<QStringList> tryLoadStringListFromDConfigInternal(
         return std::nullopt;   // Type mismatch
     }
     // No need to delete dconfigPtr, dconfigParent will manage it when it goes out of scope.
-    return value.toStringList();
+    return value.toString().split(';', Qt::SkipEmptyParts);
 }
 
 // --- Specific Loader for "supportedFileExtensions" ---

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Johnson-zs, Kakueeen

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Johnson-zs Johnson-zs merged commit ce4f563 into linuxdeepin:semantic-search Jun 23, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants