Skip to content

fix: handle DConfig list values in search utility#350

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
Johnson-zs:master
Jul 16, 2026
Merged

fix: handle DConfig list values in search utility#350
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
Johnson-zs:master

Conversation

@Johnson-zs

Copy link
Copy Markdown
Contributor
  1. Added type checking for QVariant list values in
    tryLoadStringListFromDConfigInternal
  2. Now properly handles both JSON array format (list type) and
    semicolon-delimited strings
  3. The issue occurred when DConfig stored values as JSON arrays -
    toString() would return empty
  4. Now uses toStringList() for list-type values to correctly parse the
    configuration

Influence:

  1. Test search functionality with DConfig settings in both JSON array
    format
  2. Verify semicolon-delimited string parsing remains unchanged
  3. Check configuration loading from different DConfig value formats

fix: 修复搜索工具中DConfig列表值的处理

  1. 在tryLoadStringListFromDConfigInternal中添加了对QVariant列表值的类型
    检查
  2. 现在能正确处理JSON数组格式(列表类型)和分号分隔的字符串
  3. 当DConfig以JSON数组格式存储值时会出现问题 - toString()会返回空值
  4. 现在对列表类型值使用toStringList()以正确解析配置

Influence:

  1. 测试使用JSON数组格式的DConfig设置的搜索功能
  2. 验证分号分隔字符串的解析保持不变
  3. 检查从不同DConfig值格式加载配置的情况

1. Added type checking for QVariant list values in
tryLoadStringListFromDConfigInternal
2. Now properly handles both JSON array format (list type) and
semicolon-delimited strings
3. The issue occurred when DConfig stored values as JSON arrays -
toString() would return empty
4. Now uses toStringList() for list-type values to correctly parse the
configuration

Influence:
1. Test search functionality with DConfig settings in both JSON array
format
2. Verify semicolon-delimited string parsing remains unchanged
3. Check configuration loading from different DConfig value formats

fix: 修复搜索工具中DConfig列表值的处理

1. 在tryLoadStringListFromDConfigInternal中添加了对QVariant列表值的类型
检查
2. 现在能正确处理JSON数组格式(列表类型)和分号分隔的字符串
3. 当DConfig以JSON数组格式存储值时会出现问题 - toString()会返回空值
4. 现在对列表类型值使用toStringList()以正确解析配置

Influence:
1. 测试使用JSON数组格式的DConfig设置的搜索功能
2. 验证分号分隔字符串的解析保持不变
3. 检查从不同DConfig值格式加载配置的情况

@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 @Johnson-zs, 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

[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.

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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码修复了DConfig值解析的BUG并补充了完善的单元测试,整体质量优秀
逻辑正确且无安全漏洞,但移除了原有的调试日志输出,略微降低了可调试性,扣5分

■ 【详细分析】

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

parseVariantToStringList 函数在 searchutility.cpp 中正确判断了 QVariant 的类型,针对 QVariant::ListQVariant::StringList 使用了 toStringList(),其余可转换类型回退到 toString().split(';'),彻底修复了原 BUG。tst_dconfig_parsing.cpp 中的测试用例覆盖了分号分隔字符串、单值、列表、空值及无效类型等场景,断言准确。
潜在问题:无
建议:无需修改

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

新增的函数命名规范,注释清晰说明了函数用途及背景。将解析逻辑提取为独立函数并增加单元测试,显著提升了代码的可维护性和可测试性。
潜在问题:重构 tryLoadStringListFromDConfigInternal 时移除了原有的 qDebugqWarning 日志输出,当解析失败返回 std::nullopt 时,调用方无法直接获取失败原因,降低了问题排查的便利性。
建议:在 tryLoadStringListFromDConfigInternal 调用 parseVariantToStringList 后,根据返回值补充必要的日志输出,或者在 parseVariantToStringList 中增加可选的日志记录机制。

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

类型判断和转换操作均为轻量级操作,未引入额外的性能开销。字符串分割和列表转换逻辑高效。
潜在问题:无
建议:无需修改

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次代码变更仅涉及内部数据类型的解析处理,未引入外部输入直接参与系统调用或内存操作,不存在安全风险。

  • 建议:无需修改

■ 【改进建议代码示例】

// src/dfm-search/dfm-search-lib/utils/searchutility.cpp

static std::optional<QStringList> tryLoadStringListFromDConfigInternal(
    ...
    QVariant value = dconfigPtr->value(keyName);

    // No need to delete dconfigPtr, dconfigParent will manage it when it goes out of scope.
    auto result = SearchUtility::parseVariantToStringList(value);
    
    if (!result.has_value()) {
        if (!value.isValid()) {
            qDebug() << "DConfig: Key '" << keyName << "' not found in appId:" << appId << "schemaId:" << schemaId;
        } else {
            qWarning() << "DConfig: Value for key '" << keyName << "' in appId:" << appId << "schemaId:" << schemaId
                       << "cannot be converted to QStringList. Actual type:" << value.typeName();
        }
    }
    
    return result;
}

@Johnson-zs

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit 94caf1f into linuxdeepin:master Jul 16, 2026
22 of 23 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.

2 participants