Skip to content

fix: resolve DDE help topics with fallback candidates - #634

Merged
lzwind merged 1 commit into
linuxdeepin:masterfrom
robertkill:fix/bug-368805-help-topic
Jul 8, 2026
Merged

fix: resolve DDE help topics with fallback candidates#634
lzwind merged 1 commit into
linuxdeepin:masterfrom
robertkill:fix/bug-368805-help-topic

Conversation

@robertkill

Copy link
Copy Markdown
Contributor

fix: resolve DDE help topics with fallback candidates

  1. Add DDE control center page keys to the manual title mapping table
  2. Resolve DDE-only OpenTitle candidate chains with raw and translated title matching
  3. Keep non-DDE applications on the original single-title help resolution path

Influence:

  1. Test DDE input method add-ons, shortcuts, VPN and full runtime help topic sweep
  2. Verify deepin-terminal help does not use the DDE candidate chain
  3. Verify the final package contains no BUG368805 trace logging

fix: 支持 DDE 帮助主题候选链解析

  1. 在手册标题映射表中补充 DDE 控制中心页面 key
  2. 仅对 DDE 的 OpenTitle 候选链执行原始标题和翻译标题匹配
  3. 保持非 DDE 应用原有的单标题帮助解析路径

Influence:

  1. 测试 DDE 输入法附加组件、快捷键、VPN 以及全量运行时帮助主题扫描
  2. 验证 deepin-terminal 帮助不会使用 DDE 候选链
  3. 验证最终包不包含 BUG368805 临时日志

PMS: BUG-368805

@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 @robertkill, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@lzwind lzwind left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

处理下ai review问题

@lzwind
lzwind force-pushed the fix/bug-368805-help-topic branch from 788b533 to 7966f40 Compare July 8, 2026 06:03
1. Add DDE control center page keys to the manual title mapping table
2. Resolve DDE-only OpenTitle candidate chains with raw and translated title matching
3. Keep non-DDE applications on the original single-title help resolution path

Influence:
1. Test DDE input method add-ons, shortcuts, VPN and full runtime help topic sweep
2. Verify deepin-terminal help does not use the DDE candidate chain
3. Verify the final package contains no BUG368805 trace logging

fix: 支持 DDE 帮助主题候选链解析

1. 在手册标题映射表中补充 DDE 控制中心页面 key
2. 仅对 DDE 的 OpenTitle 候选链执行原始标题和翻译标题匹配
3. 保持非 DDE 应用原有的单标题帮助解析路径

Influence:
1. 测试 DDE 输入法附加组件、快捷键、VPN 以及全量运行时帮助主题扫描
2. 验证 deepin-terminal 帮助不会使用 DDE 候选链
3. 验证最终包不包含 BUG368805 临时日志

PMS: BUG-368805
@robertkill
robertkill force-pushed the fix/bug-368805-help-topic branch from 7966f40 to 4799325 Compare July 8, 2026 06:24
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:85分

■ 【总体评价】

代码修复了帮助手册锚点匹配失败问题并消除了选择器注入风险,但存在数据冗余和已知遗留缺陷。
逻辑改进明显但因数据冗余和遗留代码缺陷扣15分。

■ 【详细分析】

  • 1.语法逻辑(基本正确)✓

JS逻辑重构正确处理了多候选标题的回退机制,有效解决了新增子模块无法匹配的问题。src/web/toManual/js/App.js中通过getAttribute替代直接拼接选择器,避免了特殊字符导致的语法错误。src/base/utils.cpp中补充了大量缺失的子模块映射键值。
潜在问题:findHashByTitle函数在遇到多个相同文本节点时返回第一个匹配项的ID,而原代码循环覆盖变量会返回最后一个匹配项的ID,此行为变更可能导致特定场景下定位锚点发生变化;根据上下文提示,src/base/utils.cpp第154行遍历languageArr匹配成功后缺少break语句跳出循环,导致无效遍历。
建议:在src/base/utils.cpp匹配成功赋值后立即增加break语句;确认前端多节点匹配时取首个还是末尾的业务需求,若需保持原逻辑可倒序遍历titleNodes

  • 2.代码质量(一般)✕

前端代码消除了原有的Promise反模式,将异步回调改为顺序递归验证,代码结构更清晰。但后端数据维护质量较差。
潜在问题:src/base/utils.cpp中新增了数十个如onPoweronBatterywakeupSettingsTitle等电源管理子模块,其对应的多语言翻译完全重复(如均映射为"电源管理"/"Power"),严重违反DRY原则,增加后续维护成本;App.jsopenCandidate使用递归实现遍历,虽然候选数量少不会栈溢出,但不够规范。
建议:将utils.cpp中重复的翻译值提取为常量或采用默认值回退机制,减少硬编码冗余;将App.js中的openCandidate递归调用改为whilefor循环迭代。

  • 3.代码性能(良好)✓

前端DOM查询优化效果显著,原代码在未命中时会执行两次querySelectorAll,新代码通过d.querySelectorAll('[text]')一次性获取所有标题节点并在内存中过滤,减少了DOM查询开销。
建议:无需额外优化,当前DOM节点单次提取已是最优解。

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 1 个,持平 0 个
总体风险描述:无安全风险。原代码使用d.querySelectorAll('[text="${title}"]')进行DOM查询,若title中包含双引号或方括号等特殊字符,可能导致CSS选择器注入,被利用来读取或修改非预期的DOM节点。新代码改为获取全量节点后通过getAttribute('text') === targetTitle进行严格字符串比对,彻底消除了该注入向量。
建议:保持当前安全的属性比对方式,后续涉及DOM查询时禁止将外部变量直接拼接进选择器字符串中。

■ 【改进建议代码示例】

// src/base/utils.cpp 匹配逻辑修复
    QString strRet = titleUS;
    QString strlocal(QLocale::system().name());
    int nCount = sizeof(languageArr) / sizeof(languageArr[0]);
    for (int i = 0; i < nCount; i++) {
        if (languageArr[i][0] == titleUS) {
            if (0 == strlocal.compare("ug_CN") || 0 == strlocal.compare("bo_CN") || 0 == strlocal.compare("zh_CN")) {
                strRet = languageArr[i][1];
            } else if (0 == strlocal.compare("zh_HK")) {
                strRet = languageArr[i][3];
            } else if (0 == strlocal.compare("zh_TW")) {
                strRet = languageArr[i][4];
            } else {
                strRet = languageArr[i][2];
            }
            break; // 增加break语句,找到匹配项后立即跳出循环,避免无效遍历
        }
    }
// src/web/toManual/js/App.js 将递归改为迭代循环
                        const titleNodes = d.querySelectorAll('[text]');
                        const findHashByTitle = (targetTitle) => {
                            for (let i = 0; i < titleNodes.length; i++) {
                                if (titleNodes[i].getAttribute('text') === targetTitle) {
                                    return titleNodes[i].id;
                                }
                            }
                            return null;
                        };

                        // 使用异步自执行函数替代递归,避免调用栈过深且逻辑更直观
                        (async () => {
                            for (let i = 0; i < candidates.length; i++) {
                                const candidate = candidates[i];
                                let hashID = findHashByTitle(candidate);
                                
                                if (hashID === null) {
                                    // 包装为Promise等待异步翻译结果
                                    hashID = await new Promise(resolve => {
                                        global.qtObjects.manual.translateTitle(candidate, titleTr => {
                                            resolve(findHashByTitle(titleTr));
                                        });
                                    });
                                }

                                if (hashID !== null) {
                                    global.open(file, hashID);
                                    return;
                                }
                            }
                            // 所有候选均未命中,回退到顶部
                            global.open(file, 'h0');
                        })();

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: caixr23, lzwind, robertkill

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

@lzwind
lzwind merged commit 242c586 into linuxdeepin:master Jul 8, 2026
17 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.

4 participants