fix: 修复 git-diff-service 硬编码路径分隔符导致 Windows 预览空白的问题#422
Merged
ErlichLiu merged 1 commit intoMay 12, 2026
Merged
Conversation
…lity in git-diff-service
normalizeSafePath、computeSource 和 candidateRoots 中使用硬编码 `/`
拼接路径分隔符,导致 Windows 上 realpathSync 返回的 `\` 路径无法通过
startsWith 前缀匹配,所有 git diff 预览均返回空内容。
- normalizeSafePath: rootWithSep 改用 sep 拼接
- computeSource: sessionPath/workspaceFilesPath 前缀改用 sep
- candidateRoots: 正则兼容两种分隔符,拼接改用 sep
- gitRootNames: split('/').pop() 改为 basename() 跨平台取仓库名
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
修复
git-diff-service.ts中因硬编码/路径分隔符导致的 Windows 兼容性问题。在 Windows 上,realpathSync和path.join返回\分隔的路径,而normalizeSafePath和computeSource使用硬编码/做startsWith前缀匹配,导致所有路径被判定为"不安全"而拒绝,git diff 预览功能在 Windows 上完全失效。Changes
apps/electron/src/main/lib/git-diff-service.tsnormalizeSafePath—rootWithSep改用sep拼接,确保与realpathSync返回的分隔符一致computeSource—sessionPath/workspaceFilesPath前缀改用sep,确保与join()结果的分隔符一致candidateRoots— 正则改为[/\\\\]+$兼容两种分隔符,拼接改用sepgitRootNames—split('/').pop()改为basename(),跨平台正确提取仓库名Impact
sep === '/',行为不变)How to Test
🤖 Generated with Claude Code