mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-19 16:18:11 +00:00
fix(gitdiff): unquote C-quoted paths from git diff-tree --raw (#39781)
`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. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
co-authored by
wxiaoguang
parent
76f8dc38e7
commit
c6069f8d9f
+11
-7
@@ -56,13 +56,17 @@ func parseLsTreeLine(line []byte) (*LsTreeEntry, error) {
|
||||
return nil, fmt.Errorf("invalid ls-tree output (invalid object id): %q, err: %w", line, err)
|
||||
}
|
||||
|
||||
if len(entryName) > 0 && entryName[0] == '"' {
|
||||
entry.Name, err = strconv.Unquote(string(entryName))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid ls-tree output (invalid name): %q, err: %w", line, err)
|
||||
}
|
||||
} else {
|
||||
entry.Name = string(entryName)
|
||||
entry.Name, err = UnquoteDiffFilePath(string(entryName))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid ls-tree output (invalid name): %q, err: %w", line, err)
|
||||
}
|
||||
return entry, nil
|
||||
}
|
||||
|
||||
func UnquoteDiffFilePath(path string) (string, error) {
|
||||
// ref: see the document of git config's "core.quotepath"
|
||||
if !strings.HasPrefix(path, `"`) {
|
||||
return path, nil
|
||||
}
|
||||
return strconv.Unquote(path)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user