MM-23489 Fix poor Unicode handling in display names (#14214)
Filter blacklisted Unicode characters from: user: first name, last name, nickname, bot description, username team: name, display name, description, company name channel: name, display name
Этот коммит содержится в:
@@ -4,6 +4,7 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"reflect"
|
||||
@@ -736,3 +737,33 @@ func checkNowhereNil(t *testing.T, name string, value interface{}) bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
func TestSanitizeUnicode(t *testing.T) {
|
||||
buf := bytes.Buffer{}
|
||||
buf.WriteString("Hello")
|
||||
buf.WriteRune(0x1d173)
|
||||
buf.WriteRune(0x1d17a)
|
||||
buf.WriteString(" there.")
|
||||
|
||||
musicArg := buf.String()
|
||||
musicWant := "Hello there."
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
arg string
|
||||
want string
|
||||
}{
|
||||
{name: "empty string", arg: "", want: ""},
|
||||
{name: "ascii only", arg: "Hello There", want: "Hello There"},
|
||||
{name: "allowed unicode", arg: "Ādam likes Iñtërnâtiônàližætiøn", want: "Ādam likes Iñtërnâtiônàližætiøn"},
|
||||
{name: "allowed unicode escaped", arg: "\u00eaI like hats\u00e2", want: "êI like hatsâ"},
|
||||
{name: "blacklist char, don't reverse string", arg: "\u202E2resu", want: "2resu"},
|
||||
{name: "blacklist chars, scoping musical notation", arg: musicArg, want: musicWant},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := SanitizeUnicode(tt.arg)
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user