From bed623600d18dac84d17e41a47a8119098dc1d47 Mon Sep 17 00:00:00 2001 From: Kjell Kvinge Date: Sat, 21 Jul 2018 20:17:10 +0200 Subject: [PATCH] Accept 'Data:' in commit graph (#4487) --- models/graph.go | 2 +- models/graph_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/models/graph.go b/models/graph.go index cfd583ca8b..8ecea9c093 100644 --- a/models/graph.go +++ b/models/graph.go @@ -66,7 +66,7 @@ func graphItemFromString(s string, r *git.Repository) (GraphItem, error) { var ascii string var data = "|||||||" - lines := strings.Split(s, "DATA:") + lines := strings.SplitN(s, "DATA:", 2) switch len(lines) { case 1: diff --git a/models/graph_test.go b/models/graph_test.go index 47c9dbb084..0f6e338792 100644 --- a/models/graph_test.go +++ b/models/graph_test.go @@ -5,6 +5,7 @@ package models import ( + "fmt" "testing" "code.gitea.io/git" @@ -43,3 +44,32 @@ func BenchmarkParseCommitString(b *testing.B) { } } } + +func TestCommitStringParsing(t *testing.T) { + dataFirstPart := "* DATA:||4e61bacab44e9b4730e44a6615d04098dd3a8eaf|2016-12-20 21:10:41 +0100|Author|user@mail.something|4e61bac|" + tests := []struct { + shouldPass bool + testName string + commitMessage string + }{ + {true, "normal", "not a fancy message"}, + {true, "extra pipe", "An extra pipe: |"}, + {true, "extra 'Data:'", "DATA: might be trouble"}, + } + + for _, test := range tests { + + t.Run(test.testName, func(t *testing.T) { + testString := fmt.Sprintf("%s%s", dataFirstPart, test.commitMessage) + graphItem, err := graphItemFromString(testString, nil) + if err != nil && test.shouldPass { + t.Errorf("Could not parse %s", testString) + return + } + + if test.commitMessage != graphItem.Subject { + t.Errorf("%s does not match %s", test.commitMessage, graphItem.Subject) + } + }) + } +}