mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-16 08:02:17 +09:00
Backport #39781 by @SudhanshuMatrix ## What `parseGitDiffTreeLine` (`services/gitdiff/git_diff_tree.go`) read `BasePath`/`HeadPath` straight from `git diff-tree --raw` output without undoing git's C-quoting, unlike its sibling `parseLsTreeLine` (`modules/git/parse.go`), which already does this with `strconv.Unquote`. This fix applies the same unquoting to both paths in the diff-tree parser. ## Why With the default `core.quotePath=true`, git C-quotes **any path containing a non-ASCII byte** — not just tabs/newlines/backslashes. That means any file with a CJK, Cyrillic, accented-Latin, or emoji name gets octal-escaped, e.g.: ``` :100644 100644 b6fc4c6... 04fea06... M "\346\227\245\346\234\254\350\252\236.txt" ``` (`日本語.txt`, confirmed against real `git diff-tree --raw` output) `GetDiffTree` backs the file-tree sidebar on the commit, compare, and pull request diff pages (`routers/web/repo/commit.go`, `compare.go`, `pull.go`). Without unquoting, any such file shows its mangled, escaped name instead of the real one, and the wrong path can throw off jump-to-file and viewed-file-state behavior that key off the path. Co-authored-by: Shudhanshu Singh <sudhanshuwriterblc@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
co-authored by
Shudhanshu Singh
wxiaoguang
parent
74e7e813c3
commit
26f537dea6
@@ -324,6 +324,22 @@ func TestParseGitDiffTree(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
// make sure our code can unquote paths no matter core.quotePath is true or false: quoted chars are like "\t" or "\{oct}"
|
||||
Name: "file modified with a C-quoted path",
|
||||
GitOutput: ":100644 100644 b6fc4c620b67d95f953a5c1c1230aaab5db5a1b0 04fea06420ca60892f73becee3614f6d023a4b7f M\t" + `"\346\227\245\346\234\254\350\252\236\ttest.txt"`,
|
||||
Expected: []*DiffTreeRecord{
|
||||
{
|
||||
Status: "modified",
|
||||
HeadPath: "日本語\ttest.txt",
|
||||
BasePath: "日本語\ttest.txt",
|
||||
HeadMode: git.EntryModeBlob,
|
||||
BaseMode: git.EntryModeBlob,
|
||||
HeadBlobID: "04fea06420ca60892f73becee3614f6d023a4b7f",
|
||||
BaseBlobID: "b6fc4c620b67d95f953a5c1c1230aaab5db5a1b0",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "no changes",
|
||||
GitOutput: ``,
|
||||
|
||||
Reference in New Issue
Block a user