From ce4ca45ab6ad1d2c2350e3fb3f91a00b000139cb Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Mon, 27 Mar 2017 12:30:40 +0100 Subject: plumbing: Use ReadBytes() rather than ReadSlice() --- plumbing/object/commit.go | 2 +- plumbing/object/commit_test.go | 17 +++++++++++++++++ plumbing/object/tag.go | 2 +- plumbing/object/tag_test.go | 17 +++++++++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/plumbing/object/commit.go b/plumbing/object/commit.go index fff4f53..7507bc7 100644 --- a/plumbing/object/commit.go +++ b/plumbing/object/commit.go @@ -130,7 +130,7 @@ func (c *Commit) Decode(o plumbing.EncodedObject) (err error) { var message bool for { - line, err := r.ReadSlice('\n') + line, err := r.ReadBytes('\n') if err != nil && err != io.EOF { return err } diff --git a/plumbing/object/commit_test.go b/plumbing/object/commit_test.go index d30e1c4..8b4ee2a 100644 --- a/plumbing/object/commit_test.go +++ b/plumbing/object/commit_test.go @@ -2,6 +2,7 @@ package object import ( "io" + "strings" "time" "github.com/src-d/go-git-fixtures" @@ -167,3 +168,19 @@ func (s *SuiteCommit) TestCommitIterNext(c *C) { c.Assert(err, Equals, io.EOF) c.Assert(commit, IsNil) } + +func (s *SuiteCommit) TestLongCommitMessageSerialization(c *C) { + encoded := &plumbing.MemoryObject{} + decoded := &Commit{} + commit := *s.Commit + + longMessage := "my message: message\n\n" + strings.Repeat("test", 4096) + "\nOK" + commit.Message = longMessage + + err := commit.Encode(encoded) + c.Assert(err, IsNil) + + err = decoded.Decode(encoded) + c.Assert(err, IsNil) + c.Assert(decoded.Message, Equals, longMessage) +} diff --git a/plumbing/object/tag.go b/plumbing/object/tag.go index 2feeea7..7b091d0 100644 --- a/plumbing/object/tag.go +++ b/plumbing/object/tag.go @@ -90,7 +90,7 @@ func (t *Tag) Decode(o plumbing.EncodedObject) (err error) { r := bufio.NewReader(reader) for { - line, err := r.ReadSlice('\n') + line, err := r.ReadBytes('\n') if err != nil && err != io.EOF { return err } diff --git a/plumbing/object/tag_test.go b/plumbing/object/tag_test.go index deb961e..f121ce9 100644 --- a/plumbing/object/tag_test.go +++ b/plumbing/object/tag_test.go @@ -3,6 +3,7 @@ package object import ( "fmt" "io" + "strings" "time" "github.com/src-d/go-git-fixtures" @@ -269,3 +270,19 @@ func (s *TagSuite) TestTagToTagString(c *C) { "\n"+ "\n") } + +func (s *TagSuite) TestLongTagNameSerialization(c *C) { + encoded := &plumbing.MemoryObject{} + decoded := &Tag{} + tag := s.tag(c, plumbing.NewHash("b742a2a9fa0afcfa9a6fad080980fbc26b007c69")) + + longName := "my tag: name " + strings.Repeat("test", 4096) + " OK" + tag.Name = longName + + err := tag.Encode(encoded) + c.Assert(err, IsNil) + + err = decoded.Decode(encoded) + c.Assert(err, IsNil) + c.Assert(decoded.Name, Equals, longName) +} -- cgit