Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

packp/capability: trim spaces on capabilities decode. #170

Merged
merged 1 commit into from
Dec 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions plumbing/protocol/packp/capability/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 9 additions & 0 deletions plumbing/protocol/packp/capability/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down