Skip to content

A platform for community discussion. Free, open, simple.

FIX: Do not truncate encoded slugs

Rafael dos Santos Silva2304dcf993f6
diff --git a/lib/slug.rb b/lib/slug.rb
index 8436f74ebce..f50492bddfd 100644
--- a/lib/slug.rb
+++ b/lib/slug.rb
@@ -9,6 +9,10 @@ module Slug
def self.for(string, default = 'topic', max_length = MAX_LENGTH)
string = string.gsub(/:([\w\-+]+(?::t\d)?):/, '') if string.present? # strip emoji strings
+ if SiteSetting.slug_generation_method == 'encoded'
+ max_length = 9999 # do not truncate encoded slugs
+ end
+
slug =
case (SiteSetting.slug_generation_method || :ascii).to_sym
when :ascii then self.ascii_generator(string)
diff --git a/spec/components/slug_spec.rb b/spec/components/slug_spec.rb
index dba8bcb6f57..699d3e0c6b2 100644
--- a/spec/components/slug_spec.rb
+++ b/spec/components/slug_spec.rb
@@ -81,6 +81,11 @@ describe Slug do
it "kills the trailing dash" do
expect(Slug.for("2- -this!~-_|,we-#-=^-")).to eq('2-this-we')
end
+
+ it "returns a slug that can be used in a valid URL" do
+ slug = Slug.for("Γνωμη για αγορα μπουζουκιου μεσω ιντερνετ και εκτίμηση")
+ expect { URI.parse("http://example.com/#{slug}") }.not_to raise_error
+ end
end
context 'none generator' do