Skip to content

Commit bed6236

Browse files
kjellkvingetechknowlogick
authored andcommitted
Accept 'Data:' in commit graph (#4487)
1 parent 5fa403c commit bed6236

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

models/graph.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func graphItemFromString(s string, r *git.Repository) (GraphItem, error) {
6666

6767
var ascii string
6868
var data = "|||||||"
69-
lines := strings.Split(s, "DATA:")
69+
lines := strings.SplitN(s, "DATA:", 2)
7070

7171
switch len(lines) {
7272
case 1:

models/graph_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package models
66

77
import (
8+
"fmt"
89
"testing"
910

1011
"code.gitea.io/git"
@@ -43,3 +44,32 @@ func BenchmarkParseCommitString(b *testing.B) {
4344
}
4445
}
4546
}
47+
48+
func TestCommitStringParsing(t *testing.T) {
49+
dataFirstPart := "* DATA:||4e61bacab44e9b4730e44a6615d04098dd3a8eaf|2016-12-20 21:10:41 +0100|Author|[email protected]|4e61bac|"
50+
tests := []struct {
51+
shouldPass bool
52+
testName string
53+
commitMessage string
54+
}{
55+
{true, "normal", "not a fancy message"},
56+
{true, "extra pipe", "An extra pipe: |"},
57+
{true, "extra 'Data:'", "DATA: might be trouble"},
58+
}
59+
60+
for _, test := range tests {
61+
62+
t.Run(test.testName, func(t *testing.T) {
63+
testString := fmt.Sprintf("%s%s", dataFirstPart, test.commitMessage)
64+
graphItem, err := graphItemFromString(testString, nil)
65+
if err != nil && test.shouldPass {
66+
t.Errorf("Could not parse %s", testString)
67+
return
68+
}
69+
70+
if test.commitMessage != graphItem.Subject {
71+
t.Errorf("%s does not match %s", test.commitMessage, graphItem.Subject)
72+
}
73+
})
74+
}
75+
}

0 commit comments

Comments
 (0)