3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-11 06:29:29 +01:00

Merge pull request #1356 from slingamn/kline

validate normalized masks as IRC params
This commit is contained in:
Shivaram Lingamneni 2020-10-26 11:58:45 -07:00 committed by GitHub
commit 6a5ba82f29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -15,6 +15,8 @@ import (
"golang.org/x/text/secure/precis"
"golang.org/x/text/unicode/norm"
"golang.org/x/text/width"
"github.com/oragono/oragono/irc/utils"
)
const (
@ -270,7 +272,11 @@ func CanonicalizeMaskWildcard(userhost string) (expanded string, err error) {
if host != "*" {
host = strings.ToLower(host)
}
return fmt.Sprintf("%s!%s@%s", nick, user, host), nil
expanded = fmt.Sprintf("%s!%s@%s", nick, user, host)
if utils.SafeErrorParam(expanded) != expanded {
err = errInvalidCharacter
}
return
}
func foldASCII(str string) (result string, err error) {

View File

@ -193,7 +193,7 @@ func TestSkeleton(t *testing.T) {
func TestCanonicalizeMaskWildcard(t *testing.T) {
tester := func(input, expected string, expectedErr error) {
out, err := CanonicalizeMaskWildcard(input)
if out != expected {
if expectedErr == nil && out != expected {
t.Errorf("expected %s to canonicalize to %s, instead %s", input, expected, out)
}
if err != expectedErr {
@ -216,6 +216,10 @@ func TestCanonicalizeMaskWildcard(t *testing.T) {
tester("Shivaram*", "shivaram*!*@*", nil)
tester("*SHIVARAM*", "*shivaram*!*@*", nil)
tester("*SHIVARAM* ", "*shivaram*!*@*", nil)
tester(":shivaram", "", errInvalidCharacter)
tester("shivaram!us er@host", "", errInvalidCharacter)
tester("shivaram!user@ho st", "", errInvalidCharacter)
}
func validFoldTester(first, second string, equal bool, folder func(string) (string, error), t *testing.T) {