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
Этот коммит содержится в:
Doug Lauder
2020-04-07 16:56:07 -04:00
коммит произвёл GitHub
родитель 84859e7159
Коммит e2d1af17de
8 изменённых файлов: 296 добавлений и 2 удалений

Просмотреть файл

@@ -317,6 +317,64 @@ func TestPatchChannel(t *testing.T) {
CheckForbiddenStatus(t, resp)
}
func TestChannelUnicodeNames(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
Client := th.Client
team := th.BasicTeam
t.Run("create channel unicode", func(t *testing.T) {
channel := &model.Channel{
Name: "\u206cenglish\u206dchannel",
DisplayName: "The \u206cEnglish\u206d Channel",
Type: model.CHANNEL_OPEN,
TeamId: team.Id}
rchannel, resp := Client.CreateChannel(channel)
CheckNoError(t, resp)
CheckCreatedStatus(t, resp)
require.Equal(t, "englishchannel", rchannel.Name, "bad unicode should be filtered from name")
require.Equal(t, "The English Channel", rchannel.DisplayName, "bad unicode should be filtered from display name")
})
t.Run("update channel unicode", func(t *testing.T) {
channel := &model.Channel{
DisplayName: "Test API Name",
Name: GenerateTestChannelName(),
Type: model.CHANNEL_OPEN,
TeamId: team.Id,
}
channel, _ = Client.CreateChannel(channel)
channel.Name = "\u206ahistorychannel"
channel.DisplayName = "UFO's and \ufff9stuff\ufffb."
newChannel, resp := Client.UpdateChannel(channel)
CheckNoError(t, resp)
require.Equal(t, "historychannel", newChannel.Name, "bad unicode should be filtered from name")
require.Equal(t, "UFO's and stuff.", newChannel.DisplayName, "bad unicode should be filtered from display name")
})
t.Run("patch channel unicode", func(t *testing.T) {
patch := &model.ChannelPatch{
Name: new(string),
DisplayName: new(string),
Header: new(string),
Purpose: new(string),
}
*patch.Name = "\u206ecommunitychannel\u206f"
*patch.DisplayName = "Natalie Tran's \ufffcAwesome Channel"
channel, resp := Client.PatchChannel(th.BasicChannel.Id, patch)
CheckNoError(t, resp)
require.Equal(t, "communitychannel", channel.Name, "bad unicode should be filtered from name")
require.Equal(t, "Natalie Tran's Awesome Channel", channel.DisplayName, "bad unicode should be filtered from display name")
})
}
func TestCreateDirectChannel(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()