Skip to content

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

FIX: Don't allow category slugs to be entirely digits

Daniel Waterworth226fc07a1763
diff --git a/lib/slug.rb b/lib/slug.rb
index f50492bddfd..25f2325b0f1 100644
--- a/lib/slug.rb
+++ b/lib/slug.rb
@@ -19,8 +19,6 @@ module Slug
when :encoded then self.encoded_generator(string)
when :none then self.none_generator(string)
end
- # Reject slugs that only contain numbers, because they would be indistinguishable from id's.
- slug = (slug =~ /[^\d]/ ? slug : '')
slug = self.prettify_slug(slug, max_length: max_length)
slug.blank? ? default : slug
end
@@ -33,6 +31,9 @@ module Slug
private
def self.prettify_slug(slug, max_length:)
+ # Reject slugs that only contain numbers, because they would be indistinguishable from id's.
+ slug = (slug =~ /[^\d]/ ? slug : '')
+
slug
.tr("_", "-")
.truncate(max_length, omission: '')