From 226fc07a1763732c113e83aff98d2195ea395d95 Mon Sep 17 00:00:00 2001 From: Daniel Waterworth Date: Wed, 4 Dec 2019 01:22:29 +0000 Subject: [PATCH] FIX: Don't allow category slugs to be entirely digits --- lib/slug.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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: '')