aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing
diff options
context:
space:
mode:
Diffstat (limited to 'plumbing')
-rw-r--r--plumbing/object/object.go8
-rw-r--r--plumbing/object/object_test.go10
2 files changed, 16 insertions, 2 deletions
diff --git a/plumbing/object/object.go b/plumbing/object/object.go
index 8bdbb2a..faf7e7f 100644
--- a/plumbing/object/object.go
+++ b/plumbing/object/object.go
@@ -83,12 +83,16 @@ type Signature struct {
// Decode decodes a byte slice into a signature
func (s *Signature) Decode(b []byte) {
- open := bytes.IndexByte(b, '<')
- close := bytes.IndexByte(b, '>')
+ open := bytes.LastIndexByte(b, '<')
+ close := bytes.LastIndexByte(b, '>')
if open == -1 || close == -1 {
return
}
+ if close < open {
+ return
+ }
+
s.Name = string(bytes.Trim(b[:open], " "))
s.Email = string(b[open+1 : close])
diff --git a/plumbing/object/object_test.go b/plumbing/object/object_test.go
index 04f2b73..877ae1d 100644
--- a/plumbing/object/object_test.go
+++ b/plumbing/object/object_test.go
@@ -138,6 +138,16 @@ func (s *ObjectsSuite) TestParseSignature(c *C) {
Email: "foo@bar.com",
When: time.Time{},
},
+ `crap> <foo@bar.com> 1257894000 +1000`: {
+ Name: "crap>",
+ Email: "foo@bar.com",
+ When: MustParseTime("2009-11-11 09:00:00 +1000"),
+ },
+ `><`: {
+ Name: "",
+ Email: "",
+ When: time.Time{},
+ },
``: {
Name: "",
Email: "",