Skip to content

fix: correct backslash path conversion for root paths - #397

Open
liyigang1 wants to merge 1 commit into
linuxdeepin:release/eaglefrom
liyigang1:pms/ws-2394/release-eagle
Open

liyigang1 wants to merge 1 commit into
linuxdeepin:release/eaglefrom
liyigang1:pms/ws-2394/release-eagle

Conversation

@liyigang1

@liyigang1 liyigang1 commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

说明

Summary by Sourcery

Fix URL path normalization and backslash conversion for root paths.

Bug Fixes:

  • Correct path conversion for root-prefixed paths to prevent generating duplicate leading backslashes.
  • Preserve the original URL when path transformation produces no change.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: liyigang1

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

@sourcery-ai

sourcery-ai Bot commented Sep 20, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Corrects root-path conversion by ensuring normal paths receive exactly one leading separator in backslash form, while avoiding URL updates when the binding transformation is a no-op.

Sequence diagram for root-path URL transformation

sequenceDiagram
    participant Caller
    participant DFMUtils
    participant QUrl

    Caller->>DFMUtils: bindUrlTransform(url)
    DFMUtils->>QUrl: path()
    QUrl-->>DFMUtils: urlPath
    DFMUtils->>DFMUtils: BackslashPathToNormal(urlPath)
    DFMUtils->>DFMUtils: bindPathTransform(normalPath, false)
    alt transformedPath == normalPath
        DFMUtils-->>Caller: return url
    else transformedPath changed
        DFMUtils->>DFMUtils: normalPathToBackslash(transformedPath)
        DFMUtils->>QUrl: setPath(path)
        DFMUtils-->>Caller: return transformed URL
    end
Loading

File-Level Changes

Change Details Files
Normalize root-prefixed paths before converting separators to prevent duplicate leading backslashes.
  • Strip all leading / characters before replacing / with \ and restoring a single root prefix.
  • Preserve the original URL when path transformation produces no change, avoiding unnecessary path rewriting.
src/dfm-io/dfm-io/dfmio_utils.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 98 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次变更正确修复了 normalPathToBackslash 对以 / 开头路径转换产生前导 //(实为 /\)的缺陷,并在 bindUrlTransform 中当路径无绑定映射变化时直接返回原 url,避免不必要的重写。语法逻辑正确,边界处理完善(根路径 /、多前导斜杠 //、空串均正确收敛为单个 / 前缀),无安全漏洞,OCR 审查 0 条评论。仅存轻微代码质量建议(提前返回语义缺注释、与同级分支风格略不一致),不影响功能正确性。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 无语法逻辑问题,边界处理完善。


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:

  1. src/dfm-io/dfm-io/dfmio_utils.cpp:234 - bindUrlTransform 提前返回分支返回原始 url 以保留路径格式,该非平凡语义缺少简短注释说明意图,影响可维护性
  2. src/dfm-io/dfm-io/dfmio_utils.cpp:226 - 反斜杠分支新增提前返回优化,但同级非反斜杠分支(226-229)未做对称优化,两分支风格略不一致

建议: 建议在第234行附近补充一行注释说明提前返回保留原始路径格式的意图;可考虑对非反斜杠分支做对称的提前返回优化以保持一致性(非必需)。


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 无性能瓶颈。极端多前导斜杠场景下 mid(1) 会多次分配字符串,可改用 indexOf 计算偏移一次性截取,但实际场景无需优化。


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: 无安全风险,安全合规。


💡 改进建议代码示例

// bindUrlTransform: 建议为提前返回补充注释说明语义
if (transformedPath == normalPath)
    return url;  // 无绑定映射变化,保留原始 url 路径格式,避免不必要的反斜杠重写

本报告由 AI 代码审查工具自动生成

Fix the normalPathToBackslash function to handle paths starting with "/"
correctly. Previously, when converting normal paths starting with "/" to
backslash format, the function would add an extra "/" at the beginning,
resulting in "//" at the start of the string. Now the function properly
removes the leading "/" before replacement and adds a single "/" prefix.

Specifically, the issue occurred because the function would replace all
"/" with "\\" including the first character, then add another "/" at
the front, creating an incorrect double slash. The fix checks if the
path starts with "/" and removes it before the replacement operation,
ensuring proper backslash path formatting.

Log: Fixed path format conversion for Windows-style file paths

Influence:
1. Test file operations with paths starting from root directory
2. Verify path format conversions between different path styles
3. Test navigation and file system operations using backslash paths
4. Validate that converted paths work correctly with Windows file system
APIs

fix: 修复根路径反斜杠转换问题

修复 normalPathToBackslash 函数,正确处理以"/"开头的路径。之前,当将
以"/"开头的普通路径转换为反斜杠格式时,函数会在开头添加额外的"/",导致
字符串以"//"开头。现在函数在替换操作前正确移除开头的"/",并添加单个"/"前
缀。

具体来说,问题发生的原因是函数会将所有"/"替换为"\\",包括首字符,然后在
前面添加另一个"/",创建了不正确的双斜杠。修复后的代码检查路径是否以"/"开
头,并在执行替换操作前将其移除,确保正确的反斜杠路径格式化。

Log: 修复 Windows 风格文件路径格式转换问题

Influence:
1. 测试从根目录开始的路径的文件操作
2. 验证不同路径风格之间的格式转换
3. 测试使用反斜杠路径的导航和文件系统操作
4. 验证转换后的路径能正确适用于 Windows 文件系统 API
@liyigang1
liyigang1 force-pushed the pms/ws-2394/release-eagle branch from b6cc2ac to 52dc8de Compare September 20, 2026 07:35
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