From 4f16cc925238aae81586e917d26b8ff6b6a340bd Mon Sep 17 00:00:00 2001 From: "Santiago M. Mola" Date: Fri, 9 Dec 2016 12:59:37 +0100 Subject: packp/capability: trim spaces on capabilities decode. (#170) git 1.8 used to write a leading space in the capabilities announcement for git-receive-pack. We now trim spaces before decoding a capabilities list to be more tolerant about this kind of difference. --- plumbing/protocol/packp/capability/list.go | 5 +++++ plumbing/protocol/packp/capability/list_test.go | 9 +++++++++ 2 files changed, 14 insertions(+) (limited to 'plumbing/protocol/packp/capability') diff --git a/plumbing/protocol/packp/capability/list.go b/plumbing/protocol/packp/capability/list.go index 7197d36..2847580 100644 --- a/plumbing/protocol/packp/capability/list.go +++ b/plumbing/protocol/packp/capability/list.go @@ -48,6 +48,11 @@ func (l *List) IsEmpty() bool { // Decode decodes list of capabilities from raw into the list func (l *List) Decode(raw []byte) error { + // git 1.x receive pack used to send a leading space on its + // git-receive-pack capabilities announcement. We just trim space to be + // tolerant to space changes in different versions. + raw = bytes.TrimSpace(raw) + if len(raw) == 0 { return nil } diff --git a/plumbing/protocol/packp/capability/list_test.go b/plumbing/protocol/packp/capability/list_test.go index d6aac16..42f0179 100644 --- a/plumbing/protocol/packp/capability/list_test.go +++ b/plumbing/protocol/packp/capability/list_test.go @@ -27,6 +27,15 @@ func (s *SuiteCapabilities) TestDecode(c *check.C) { c.Assert(cap.Get(ThinPack), check.IsNil) } +func (s *SuiteCapabilities) TestDecodeWithLeadingSpace(c *check.C) { + cap := NewList() + err := cap.Decode([]byte(" report-status")) + c.Assert(err, check.IsNil) + + c.Assert(cap.m, check.HasLen, 1) + c.Assert(cap.Supports(ReportStatus), check.Equals, true) +} + func (s *SuiteCapabilities) TestDecodeEmpty(c *check.C) { cap := NewList() err := cap.Decode(nil) -- cgit