mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 07:53:49 +08:00
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:
16
lib/slug.rb
16
lib/slug.rb
@ -6,28 +6,22 @@ module Slug
|
||||
CHAR_FILTER_REGEXP = /[:\/\?#\[\]@!\$&'\(\)\*\+,;=_\.~%\\`^\s|\{\}"<>]+/ # :/?#[]@!$&'()*+,;=_.~%\`^|{}"<>
|
||||
MAX_LENGTH = 255
|
||||
|
||||
def self.for(string, default = 'topic', max_length = MAX_LENGTH)
|
||||
def self.for(string, default = 'topic', max_length = MAX_LENGTH, method: nil)
|
||||
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
|
||||
method = (method || SiteSetting.slug_generation_method || :ascii).to_sym
|
||||
max_length = 9999 if method == :encoded # do not truncate encoded slugs
|
||||
|
||||
slug =
|
||||
case (SiteSetting.slug_generation_method || :ascii).to_sym
|
||||
case method
|
||||
when :ascii then self.ascii_generator(string)
|
||||
when :encoded then self.encoded_generator(string)
|
||||
when :none then self.none_generator(string)
|
||||
end
|
||||
|
||||
slug = self.prettify_slug(slug, max_length: max_length)
|
||||
(slug.blank? || slug_is_only_numbers?(slug)) ? default : slug
|
||||
end
|
||||
|
||||
def self.sanitize(string, downcase: false, max_length: MAX_LENGTH)
|
||||
slug = self.encoded_generator(string, downcase: downcase)
|
||||
self.prettify_slug(slug, max_length: max_length)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.slug_is_only_numbers?(slug)
|
||||
|
Reference in New Issue
Block a user