aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/protocol/packp/capability
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2016-11-30 18:57:10 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2016-11-30 18:57:10 +0100
commit7de79aef5d4aa3100382d4df3e99525f9949e8d1 (patch)
tree2d218d1084d3badfd9acadfb41e61edff254428d /plumbing/protocol/packp/capability
parentbd3dd4d421299699854bfe0353aae312bcf8c97c (diff)
downloadgo-git-7de79aef5d4aa3100382d4df3e99525f9949e8d1.tar.gz
capability: support empty input on Decode. (#153)
Calling capability.List's Decode with nil input will have no effect. This is useful in other decoders, where an empty capability list is received as an empty byte slice.
Diffstat (limited to 'plumbing/protocol/packp/capability')
-rw-r--r--plumbing/protocol/packp/capability/list.go4
-rw-r--r--plumbing/protocol/packp/capability/list_test.go7
2 files changed, 11 insertions, 0 deletions
diff --git a/plumbing/protocol/packp/capability/list.go b/plumbing/protocol/packp/capability/list.go
index 73d1f25..ff8d4a4 100644
--- a/plumbing/protocol/packp/capability/list.go
+++ b/plumbing/protocol/packp/capability/list.go
@@ -48,6 +48,10 @@ func (l *List) IsEmpty() bool {
// Decode decodes list of capabilities from raw into the list
func (l *List) Decode(raw []byte) error {
+ if len(raw) == 0 {
+ return nil
+ }
+
for _, data := range bytes.Split(raw, []byte{' '}) {
pair := bytes.SplitN(data, []byte{'='}, 2)
diff --git a/plumbing/protocol/packp/capability/list_test.go b/plumbing/protocol/packp/capability/list_test.go
index 6d350b0..eeb3173 100644
--- a/plumbing/protocol/packp/capability/list_test.go
+++ b/plumbing/protocol/packp/capability/list_test.go
@@ -27,6 +27,13 @@ func (s *SuiteCapabilities) TestDecode(c *check.C) {
c.Assert(cap.Get(ThinPack), check.IsNil)
}
+func (s *SuiteCapabilities) TestDecodeEmpty(c *check.C) {
+ cap := NewList()
+ err := cap.Decode(nil)
+ c.Assert(err, check.IsNil)
+ c.Assert(cap, check.DeepEquals, NewList())
+}
+
func (s *SuiteCapabilities) TestDecodeWithErrArguments(c *check.C) {
cap := NewList()
err := cap.Decode([]byte("thin-pack=foo"))