mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-27 08:51:59 +01: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:
1 parent
76f8dc38e7
commit
c6069f8d9f
3 files changed
+40
-18
No files matched your search
@@ -123,24 +123,19 @@ func validateGitDiffTreeArguments(ctx context.Context, gitRepo *git.Repository,
|
||||
}
|
||||
|
||||
func parseGitDiffTree(gitOutput io.Reader) ([]*DiffTreeRecord, error) {
|
||||
/*
|
||||
The output of `git diff-tree --raw -r --find-renames` is of the form:
|
||||
/* The output of `git diff-tree --raw -r --find-renames` is of the form:
|
||||
:<old_mode> <new_mode> <old_sha> <new_sha> <status>\t<path>
|
||||
|
||||
:<old_mode> <new_mode> <old_sha> <new_sha> <status>\t<path>
|
||||
or for renames:
|
||||
:<old_mode> <new_mode> <old_sha> <new_sha> <status>\t<old_path>\t<new_path>
|
||||
|
||||
or for renames:
|
||||
|
||||
:<old_mode> <new_mode> <old_sha> <new_sha> <status>\t<old_path>\t<new_path>
|
||||
|
||||
See: <https://git-scm.com/docs/git-diff-tree#_raw_output_format> for more details
|
||||
*/
|
||||
See: <https://git-scm.com/docs/git-diff-tree#_raw_output_format> for more details */
|
||||
results := make([]*DiffTreeRecord, 0)
|
||||
|
||||
lines := bufio.NewScanner(gitOutput)
|
||||
for lines.Scan() {
|
||||
line := lines.Text()
|
||||
|
||||
if len(line) == 0 {
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -193,6 +188,13 @@ func parseGitDiffTreeLine(line string) (*DiffTreeRecord, error) {
|
||||
headPath = filePaths[0]
|
||||
}
|
||||
|
||||
if basePath, err = git.UnquoteDiffFilePath(basePath); err != nil {
|
||||
return nil, fmt.Errorf("unparsable output for diff-tree --raw: `%s`, invalid base path: %w", line, err)
|
||||
}
|
||||
if headPath, err = git.UnquoteDiffFilePath(headPath); err != nil {
|
||||
return nil, fmt.Errorf("unparsable output for diff-tree --raw: `%s`, invalid head path: %w", line, err)
|
||||
}
|
||||
|
||||
return &DiffTreeRecord{
|
||||
Status: status,
|
||||
Score: score,
|
||||
|
||||
Reference in new issue
Block a user