diff --git a/.travis.yml b/.travis.yml index d6064b55..041b45aa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,8 @@ language: go +go: + - "1.10.x" + install: make deps script: @@ -7,4 +10,3 @@ script: - tar -xzf goreleaser_Linux_x86_64.tar.gz -C $GOPATH/bin - make - make test -- ./.check-gofmt.sh diff --git a/irc/modes/modes.go b/irc/modes/modes.go index 287dbd44..310e46f4 100644 --- a/irc/modes/modes.go +++ b/irc/modes/modes.go @@ -340,6 +340,10 @@ func NewModeSet() *ModeSet { // test whether `mode` is set func (set *ModeSet) HasMode(mode Mode) bool { + if set == nil { + return false + } + set.RLock() defer set.RUnlock() return set.modes[mode] @@ -362,6 +366,10 @@ func (set *ModeSet) SetMode(mode Mode, on bool) (applied bool) { // return the modes in the set as a slice func (set *ModeSet) AllModes() (result []Mode) { + if set == nil { + return + } + set.RLock() defer set.RUnlock() @@ -372,22 +380,27 @@ func (set *ModeSet) AllModes() (result []Mode) { } // String returns the modes in this set. -func (set *ModeSet) String() string { +func (set *ModeSet) String() (result string) { + if set == nil { + return + } + set.RLock() defer set.RUnlock() - if len(set.modes) == 0 { - return "" - } - var result []byte + var buf strings.Builder for mode := range set.modes { - result = append(result, mode.String()...) + buf.WriteRune(rune(mode)) } - return string(result) + return buf.String() } // Prefixes returns a list of prefixes for the given set of channel modes. func (set *ModeSet) Prefixes(isMultiPrefix bool) (prefixes string) { + if set == nil { + return + } + set.RLock() defer set.RUnlock() diff --git a/irc/modes/modes_test.go b/irc/modes/modes_test.go index 8f20bdfc..216add3c 100644 --- a/irc/modes/modes_test.go +++ b/irc/modes/modes_test.go @@ -35,3 +35,16 @@ func TestSetMode(t *testing.T) { t.Errorf("unexpected modestring: %s", modeString) } } + +func TestNilReceivers(t *testing.T) { + var set ModeSet + + if set.HasMode(Invisible) { + t.Errorf("nil ModeSet should not have any modes") + } + + str := set.String() + if str != "" { + t.Errorf("nil Modeset should have empty String(), got %v instead", str) + } +}