From 152617e8db2b1e854e967d82c80c34f0adf33e61 Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 7 Jul 2020 09:13:34 +0200 Subject: [PATCH 1/3] Fix creating lists with non utf-8 characters --- pkg/models/list.go | 4 ++-- pkg/models/list_test.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) 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..c3d01b368 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 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) { -- 2.40.1 From 94e427e27fac4448d54003b48542809aa37a206d Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 7 Jul 2020 09:17:46 +0200 Subject: [PATCH 2/3] Fix migrating lists with non utf-8 characters in their name --- pkg/migration/20200516123847.go | 4 ++-- 1 file changed, 2 insertions(+), 2 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). -- 2.40.1 From e30c0f97bc4914bf5f55ec3a9dfc72e6dde4f80b Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 7 Jul 2020 09:39:06 +0200 Subject: [PATCH 3/3] Fix test name --- pkg/models/list_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/models/list_test.go b/pkg/models/list_test.go index c3d01b368..e3a804769 100644 --- a/pkg/models/list_test.go +++ b/pkg/models/list_test.go @@ -79,7 +79,7 @@ func TestList_CreateOrUpdate(t *testing.T) { assert.Error(t, err) assert.True(t, IsErrListIdentifierIsNotUnique(err)) }) - t.Run("non utf8 characters", func(t *testing.T) { + t.Run("non ascii characters", func(t *testing.T) { db.LoadAndAssertFixtures(t) list := List{ Title: "приффки фсем", -- 2.40.1