mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 08:53:44 +08:00
DEV: Refactor to add Custom emoji sanitization (#24368)
Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
This commit is contained in:
parent
51e02e0d31
commit
7992d7a65a
|
@ -16,8 +16,7 @@ class Admin::EmojisController < Admin::AdminController
|
||||||
hijack do
|
hijack do
|
||||||
# fix the name
|
# fix the name
|
||||||
name = File.basename(name, ".*")
|
name = File.basename(name, ".*")
|
||||||
name = name.gsub(/[^a-z0-9]+/i, "_").gsub(/_{2,}/, "_").downcase
|
name = Emoji.sanitize_emoji_name(name)
|
||||||
|
|
||||||
upload =
|
upload =
|
||||||
UploadCreator.new(file.tempfile, file.original_filename, type: "custom_emoji").create_for(
|
UploadCreator.new(file.tempfile, file.original_filename, type: "custom_emoji").create_for(
|
||||||
current_user.id,
|
current_user.id,
|
||||||
|
|
|
@ -324,4 +324,8 @@ class Emoji
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.sanitize_emoji_name(name)
|
||||||
|
name.gsub(/[^a-z0-9]+/i, "_").gsub(/_{2,}/, "_").downcase
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -718,7 +718,7 @@ class Plugin::Instance
|
||||||
end
|
end
|
||||||
|
|
||||||
def register_emoji(name, url, group = Emoji::DEFAULT_GROUP)
|
def register_emoji(name, url, group = Emoji::DEFAULT_GROUP)
|
||||||
name = name.gsub(/[^a-z0-9]+/i, "_").gsub(/_{2,}/, "_").downcase
|
name = Emoji.sanitize_emoji_name(name)
|
||||||
Plugin::CustomEmoji.register(name, url, group)
|
Plugin::CustomEmoji.register(name, url, group)
|
||||||
Emoji.clear_cache
|
Emoji.clear_cache
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user