Fix creating lists with non utf-8 characters

This commit is contained in:
kolaente 2020-07-07 09:13:34 +02:00
parent 96f366f5e7
commit 152617e8db
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 12 additions and 2 deletions

View File

@ -404,7 +404,7 @@ func GenerateListIdentifier(l *List, sess *xorm.Engine) (err error) {
// The general idea here is to take the title and slice it into pieces, until we found a unique piece.
var exists = true
titleSlug := strings.Replace(strings.ToUpper(l.Title), " ", "", -1)
titleSlug := []rune(strings.Replace(strings.ToUpper(l.Title), " ", "", -1))
// We can save at most 10 characters in the db, so we need to ensure it has at most 10 characters
if len(titleSlug) > 10 {
@ -421,7 +421,7 @@ func GenerateListIdentifier(l *List, sess *xorm.Engine) (err error) {
}
// Take a random part of the title slug, starting at the beginning
l.Identifier = titleSlug[i:]
l.Identifier = string(titleSlug[i:])
exists, err = sess.
Where("identifier = ?", l.Identifier).
And("id != ?", l.ID).

View File

@ -79,6 +79,16 @@ func TestList_CreateOrUpdate(t *testing.T) {
assert.Error(t, err)
assert.True(t, IsErrListIdentifierIsNotUnique(err))
})
t.Run("non utf8 characters", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
list := List{
Title: "приффки фсем",
Description: "Lorem Ipsum",
NamespaceID: 1,
}
err := list.Create(usr)
assert.NoError(t, err)
})
})
t.Run("update", func(t *testing.T) {