1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-17 07:48:35 +00:00

Fix incorrect comment diff hunk parsing, fix github asset ID nil panic (#35046)

* Fix missing the first char when parsing diff hunk header
* Fix #35040
* Fix #35049

----

Introduced in
https://github.com/go-gitea/gitea/pull/12047/files#diff-de48c2f70e24ff5603180acf8b5ce9d0356ede8a45bfbf2a485707282ace6d6aR268

Before:

<img width="487" height="167" alt="image"
src="https://github.com/user-attachments/assets/17524c76-a296-4b4b-a4f9-c5150c41bae5"
/>

After:

<img width="749" height="144" alt="image"
src="https://github.com/user-attachments/assets/bcb12c76-c1ae-40f1-81b7-183d15f891db"
/>

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Lunny Xiao
2025-07-12 06:18:41 +08:00
committed by GitHub
parent 56eccb4995
commit 1352080ef7
3 changed files with 26 additions and 11 deletions

View File

@@ -179,7 +179,7 @@ func (d *DiffLine) GetExpandDirection() DiffLineExpandDirection {
}
func getDiffLineSectionInfo(treePath, line string, lastLeftIdx, lastRightIdx int) *DiffLineSectionInfo {
leftLine, leftHunk, rightLine, righHunk := git.ParseDiffHunkString(line)
leftLine, leftHunk, rightLine, rightHunk := git.ParseDiffHunkString(line)
return &DiffLineSectionInfo{
Path: treePath,
@@ -188,7 +188,7 @@ func getDiffLineSectionInfo(treePath, line string, lastLeftIdx, lastRightIdx int
LeftIdx: leftLine,
RightIdx: rightLine,
LeftHunkSize: leftHunk,
RightHunkSize: righHunk,
RightHunkSize: rightHunk,
}
}
@@ -290,7 +290,7 @@ func (diffSection *DiffSection) GetComputedInlineDiffFor(diffLine *DiffLine, loc
// try to find equivalent diff line. ignore, otherwise
switch diffLine.Type {
case DiffLineSection:
return getLineContent(diffLine.Content[1:], locale)
return getLineContent(diffLine.Content, locale)
case DiffLineAdd:
compareDiffLine := diffSection.GetLine(diffLine.Match)
return diffSection.getDiffLineForRender(DiffLineAdd, compareDiffLine, diffLine, locale)
@@ -856,6 +856,7 @@ func parseHunks(ctx context.Context, curFile *DiffFile, maxLines, maxLineCharact
lastLeftIdx = -1
curFile.Sections = append(curFile.Sections, curSection)
// FIXME: the "-1" can't be right, these "line idx" are all 1-based, maybe there are other bugs that covers this bug.
lineSectionInfo := getDiffLineSectionInfo(curFile.Name, line, leftLine-1, rightLine-1)
diffLine := &DiffLine{
Type: DiffLineSection,