A platform for community discussion. Free, open, simple.
FIX: Clean up emoji name which is file name (#14980)
Martin Brennane7a474249059
diff --git a/app/controllers/admin/emojis_controller.rb b/app/controllers/admin/emojis_controller.rbindex 8320ea340e3..486a06c666d 100644--- a/app/controllers/admin/emojis_controller.rb+++ b/app/controllers/admin/emojis_controller.rb@@ -16,6 +16,7 @@ class Admin::EmojisController < Admin::AdminControllerhijack do# fix the name+ name = File.basename(name, ".*")name = name.gsub(/[^a-z0-9]+/i, '_').gsub(/_{2,}/, '_').downcasediff --git a/spec/requests/admin/emojis_controller_spec.rb b/spec/requests/admin/emojis_controller_spec.rbindex 39078a2fc49..45e66fd3ac4 100644--- a/spec/requests/admin/emojis_controller_spec.rb+++ b/spec/requests/admin/emojis_controller_spec.rb@@ -92,6 +92,40 @@ RSpec.describe Admin::EmojisController doexpect(response.status).to eq(200)expect(custom_emoji.group).to eq("foo")end++ it 'should fix up the emoji name' do+ Emoji.expects(:clear_cache).times(3)++ post "/admin/customize/emojis.json", params: {+ name: 'test.png',+ file: fixture_file_upload("#{Rails.root}/spec/fixtures/images/logo.png")+ }++ custom_emoji = CustomEmoji.last+ upload = custom_emoji.upload++ expect(upload.original_filename).to eq('logo.png')+ expect(custom_emoji.name).to eq("test")+ expect(response.status).to eq(200)++ post "/admin/customize/emojis.json", params: {+ name: 'st&#* onk$',+ file: fixture_file_upload("#{Rails.root}/spec/fixtures/images/logo.png")+ }++ custom_emoji = CustomEmoji.last+ expect(custom_emoji.name).to eq("st_onk_")+ expect(response.status).to eq(200)++ post "/admin/customize/emojis.json", params: {+ name: 'PaRTYpaRrot',+ file: fixture_file_upload("#{Rails.root}/spec/fixtures/images/logo.png")+ }++ custom_emoji = CustomEmoji.last+ expect(custom_emoji.name).to eq("partyparrot")+ expect(response.status).to eq(200)+ endenddescribe '#destroy' do