mirror of
https://github.com/jeremyd/ergo.git
synced 2026-07-14 19:58:11 -07:00
Assorted fixes
* Fix #679 (borked reply to `JOIN #chan,\r\n`) * Replace invalid error parameters with *'s in various places * Fix PART with no message sending an empty trailing parameter to the channel * Fix some error responses not getting labeled
This commit is contained in:
@@ -54,3 +54,12 @@ func StringToBool(str string) (result bool, err error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Checks that a parameter can be passed as a non-trailing, and returns "*"
|
||||
// if it can't. See #697.
|
||||
func SafeErrorParam(param string) string {
|
||||
if param == "" || param[0] == ':' || strings.IndexByte(param, ' ') != -1 {
|
||||
return "*"
|
||||
}
|
||||
return param
|
||||
}
|
||||
|
||||
@@ -21,3 +21,12 @@ func TestStringToBool(t *testing.T) {
|
||||
val, err = StringToBool("default")
|
||||
assertEqual(err, ErrInvalidParams, t)
|
||||
}
|
||||
|
||||
func TestSafeErrorParam(t *testing.T) {
|
||||
assertEqual(SafeErrorParam("hi"), "hi", t)
|
||||
assertEqual(SafeErrorParam("#hi"), "#hi", t)
|
||||
assertEqual(SafeErrorParam("#hi there"), "*", t)
|
||||
assertEqual(SafeErrorParam(":"), "*", t)
|
||||
assertEqual(SafeErrorParam("#hi:there"), "#hi:there", t)
|
||||
assertEqual(SafeErrorParam(""), "*", t)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user