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

Commit 491de64

Browse files
committed
client/common: fix empty panic on set at empty capability
1 parent 49f40d9 commit 491de64

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

clients/common/common.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ func (c *Capabilities) Get(capability string) *Capability {
9999

100100
// Set sets a capability removing the values
101101
func (c *Capabilities) Set(capability string, values ...string) {
102-
delete(c.m, capability)
102+
if _, ok := c.m[capability]; ok {
103+
delete(c.m, capability)
104+
}
105+
103106
c.Add(capability, values...)
104107
}
105108

clients/common/common_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ func (s *SuiteCommon) TestCapabilitiesSet(c *C) {
8282
c.Assert(cap.Get("symref").Values, DeepEquals, []string{"bar"})
8383
}
8484

85+
func (s *SuiteCommon) TestCapabilitiesSetEmpty(c *C) {
86+
cap := NewCapabilities()
87+
cap.Set("foo", "bar")
88+
89+
c.Assert(cap.Get("foo").Values, HasLen, 1)
90+
}
91+
8592
func (s *SuiteCommon) TestCapabilitiesAdd(c *C) {
8693
cap := NewCapabilities()
8794
cap.Add("symref", "foo", "qux")

0 commit comments

Comments
 (0)