summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Knapp <HamAdams@disroot.org>2022-02-16 12:09:08 -0500
committerdelthas <delthas@dille.cc>2022-02-18 16:52:35 +0100
commitfe9bc1a2167d87aed1cdef6f7eb58732f8f25ac0 (patch)
tree3a2aa3313e613050600050c68497b2b6d197bf6d
parentEnable clicking on channel members to open a query with them (diff)
Fix segfault on /mode x
Return an error instead of segfaulting when handling /mode x where x is a string that starts without + - or #
-rw-r--r--commands.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/commands.go b/commands.go
index c437087..10ae19e 100644
--- a/commands.go
+++ b/commands.go
@@ -1,6 +1,7 @@
package senpai
import (
+ "errors"
"fmt"
"sort"
"strconv"
@@ -374,11 +375,19 @@ func commandDoNick(app *App, args []string) (err error) {
}
func commandDoMode(app *App, args []string) (err error) {
- if strings.HasPrefix(args[0], "+") || strings.HasPrefix(args[0], "-") {
+ hasModePrefix := strings.HasPrefix(args[0], "+") || strings.HasPrefix(args[0], "-")
+ hasChanPrefix := strings.HasPrefix(args[0], "#")
+
+ if !hasModePrefix && !hasChanPrefix {
+ return errors.New("invalid argument")
+ }
+
+ if hasModePrefix {
// if we do eg /MODE +P, automatically insert the current channel: /MODE #<current-chan> +P
_, channel := app.win.CurrentBuffer()
args = append([]string{channel}, args...)
}
+
channel := args[0]
flags := args[1]
modeArgs := args[2:]