FIX: Make category slugs lowercase (#11277)

Admins could specify category slug with upper case characters and same slug,
but with different cases could be used simultaneously.
This commit is contained in:
Bianca Nenciu
2021-01-12 17:28:33 +02:00
committed by GitHub
parent e80332a2bc
commit ec0212e56b
7 changed files with 118 additions and 30 deletions
+7 -4
View File
@@ -343,8 +343,7 @@ class Category < ActiveRecord::Base
if slug.present?
# if we don't unescape it first we strip the % from the encoded version
slug = SiteSetting.slug_generation_method == 'encoded' ? CGI.unescape(self.slug) : self.slug
# sanitize the custom slug
self.slug = Slug.sanitize(slug)
self.slug = Slug.for(slug, '', method: :encoded)
if self.slug.blank?
errors.add(:slug, :invalid)
@@ -795,8 +794,12 @@ class Category < ActiveRecord::Base
return nil if slug_path.empty?
return nil if slug_path.size > SiteSetting.max_category_nesting
if SiteSetting.slug_generation_method == "encoded"
slug_path.map! { |slug| CGI.escape(slug) }
slug_path.map! do |slug|
if SiteSetting.slug_generation_method == "encoded"
CGI.escape(slug.downcase)
else
slug.downcase
end
end
query =