diff --git a/commit.go b/commit.go index 758cbda..f4c1a28 100644 --- a/commit.go +++ b/commit.go @@ -145,7 +145,7 @@ func (c *Commit) Decode(hash hash.Hash, from io.Reader, size int64) (n int, err c.Committer = "" } default: - if strings.HasPrefix(s.Text(), " ") { + if strings.HasPrefix(text, " ") && len(c.ExtraHeaders) > 0 { idx := len(c.ExtraHeaders) - 1 hdr := c.ExtraHeaders[idx] diff --git a/commit_test.go b/commit_test.go index 95d6631..804f8cf 100644 --- a/commit_test.go +++ b/commit_test.go @@ -455,3 +455,17 @@ func TestCommitEqualReturnsTrueWhenBothCommitsAreNil(t *testing.T) { assert.True(t, c1.Equal(c2)) } + +func TestCommitInvalidMultilineNonExtraHeader(t *testing.T) { + cc := `tree 2aedfd35087c75d17bdbaf4dd56069d44fc75b71 +parent 75158117eb8efe60453f8c077527ac3530c81e38 +author Jane Doe 1503956287 -0400 +committer Jane Doe 1503956287 -0400 + foo bar + +initial commit` + + var c Commit + _, err := c.Decode(sha1.New(), strings.NewReader(cc), int64(len(cc))) + assert.NoError(t, err) +}