[PATCH senpai] Fix segfault on /mode x
Export this patch
Return an error instead of segfaulting when handling /mode x where x
is a string that starts without + - or #
---
commands.go | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/commands.go b/commands.go
index 403aec8..8eabb97 100644
--- a/commands.go
+++ b/commands.go
@@ -1,6 +1,7 @@
package senpai
import (
+ "errors"
"fmt"
"sort"
"strconv"
@@ -395,11 +396,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:]
--
2.34.1