From 4db06ba9a1d7114b844352bde5eee115fdb0b188 Mon Sep 17 00:00:00 2001 From: konrad Date: Tue, 7 Jul 2020 07:48:12 +0000 Subject: [PATCH] Fix creating lists with non ascii characters (#607) Fix test name Fix migrating lists with non utf-8 characters in their name Fix creating lists with non utf-8 characters Co-authored-by: kolaente Reviewed-on: https://kolaente.dev/vikunja/api/pulls/607 --- pkg/migration/20200516123847.go | 4 ++-- pkg/models/list.go | 4 ++-- pkg/models/list_test.go | 10 ++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/migration/20200516123847.go b/pkg/migration/20200516123847.go index 1a724cb5c..e9eefb700 100644 --- a/pkg/migration/20200516123847.go +++ b/pkg/migration/20200516123847.go @@ -55,7 +55,7 @@ func init() { // 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 { @@ -72,7 +72,7 @@ func init() { } // 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). diff --git a/pkg/models/list.go b/pkg/models/list.go index e5c3ddd5c..6d44889a4 100644 --- a/pkg/models/list.go +++ b/pkg/models/list.go @@ -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). diff --git a/pkg/models/list_test.go b/pkg/models/list_test.go index ce87c5189..e3a804769 100644 --- a/pkg/models/list_test.go +++ b/pkg/models/list_test.go @@ -79,6 +79,16 @@ func TestList_CreateOrUpdate(t *testing.T) { assert.Error(t, err) assert.True(t, IsErrListIdentifierIsNotUnique(err)) }) + t.Run("non ascii 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) {