From 1eab3167af84fc96dbabe7b5d9c22d6d4c214800 Mon Sep 17 00:00:00 2001 From: Aymen Ben Tanfous Date: Wed, 5 Oct 2022 13:19:12 +0100 Subject: [PATCH] Fixed truncation issue (#77) --- slug.go | 2 +- slug_test.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/slug.go b/slug.go index 5a2b284..f93f636 100644 --- a/slug.go +++ b/slug.go @@ -112,7 +112,7 @@ func MakeLang(s string, lang string) (slug string) { slug = strings.ToLower(slug) } - if !EnableSmartTruncate { + if !EnableSmartTruncate && len(slug) >= MaxLength { slug = slug[:MaxLength] } diff --git a/slug_test.go b/slug_test.go index de6f984..ffb89e3 100644 --- a/slug_test.go +++ b/slug_test.go @@ -288,6 +288,7 @@ func TestSlugMakeSmartTruncate(t *testing.T) { {"Dobroslaw Zybort", 9, "dobroslaw", true}, {"Dobroslaw Zybort", 12, "dobroslaw", true}, {"Dobroslaw Zybort", 15, "dobroslaw", true}, + {"Dobroslaw Zybort", 15, "dobroslaw-zybor", false}, {"Dobroslaw Zybort", 16, "dobroslaw-zybort", true}, {"Dobroslaw Zybort", 17, "dobroslaw-zybort", true}, {"Dobroslaw Zybort", 100, "dobroslaw-zybort", true}, @@ -312,6 +313,7 @@ func TestSlugMakeSmartTruncate(t *testing.T) { {"DOBROSLAWZYBORT", 9, "dobroslaw", true}, {"DOBROSLAWZYBORT", 15, "dobroslawzybort", true}, + {"DOBROSLAWZYBORT", 17, "dobroslawzybort", false}, {"DOBROSLAWZYBORT", 100, "dobroslawzybort", true}, {" Dobroslaw Zybort ?", 12, "dobroslaw", true}, {"Ala ma 6 kotów.", 10, "ala-ma-6", true},