mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-01 05:08:58 +00:00
fix(gitdiff): prevent index out of range panic in GetLineTypeMarker (#38728)
Fixes a `runtime error: index out of range [0] with length 0` panic when executing template `repo/diff/section_unified` because `GetLineTypeMarker()` indexes into empty `DiffLine` content. The regression was introduced in PR #38706 (`94c61137e4`) where `Content: " "` was removed from the initialization of `tailDiffLine`. Guarding `GetLineTypeMarker()` directly makes Gitea defensive and robust against empty diff line values regardless of the source path. Fixes https://github.com/go-gitea/gitea/issues/38724 ### Tests - Added `TestDiffLine_GetLineTypeMarker` covering empty content, prefixes, and normal text formats. Signed-off-by: Sudhanshu Singh <sudhanshuwriterblc@gmail.com>
This commit is contained in:
@@ -170,6 +170,9 @@ func (d *DiffLine) GetCommentSide() string {
|
||||
|
||||
// GetLineTypeMarker returns the line type marker
|
||||
func (d *DiffLine) GetLineTypeMarker() string {
|
||||
if d.Content == "" {
|
||||
return ""
|
||||
}
|
||||
if strings.IndexByte(" +-", d.Content[0]) > -1 {
|
||||
return d.Content[0:1]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user