mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
FIX: prevent creation of tags with invalid characters
This commit is contained in:
parent
6ea040dd5f
commit
0328141e05
4 changed files with 72 additions and 18 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
module Slug
|
||||
|
||||
CHAR_FILTER_REGEXP = /[:\/\?#\[\]@!\$&'\(\)\*\+,;=_\.~%\\`^\s|\{\}"<>]+/ # :/?#[]@!$&'()*+,;=_.~%\`^|{}"<>
|
||||
|
||||
def self.for(string, default = 'topic')
|
||||
slug = case (SiteSetting.slug_generation_method || :ascii).to_sym
|
||||
when :ascii then self.ascii_generator(string)
|
||||
|
@ -31,7 +33,7 @@ module Slug
|
|||
# See also URI::REGEXP::PATTERN.
|
||||
string.strip
|
||||
.gsub(/\s+/, '-')
|
||||
.gsub(/[:\/\?#\[\]@!\$&'\(\)\*\+,;=_\.~%\\`^\s|\{\}"<>]+/, '') # :/?#[]@!$&'()*+,;=_.~%\`^|{}"<>
|
||||
.gsub(CHAR_FILTER_REGEXP, '')
|
||||
.gsub(/\A-+|-+\z/, '') # remove possible trailing and preceding dashes
|
||||
.squeeze('-') # squeeze continuous dashes to prettify slug
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue