diff --git a/app/controllers/admin/creator_settings_controller.rb b/app/controllers/admin/creator_settings_controller.rb index a6c3ca2f6..9631d1432 100644 --- a/app/controllers/admin/creator_settings_controller.rb +++ b/app/controllers/admin/creator_settings_controller.rb @@ -20,8 +20,7 @@ module Admin if settings_params[:logo] logo_uploader = upload_logo(settings_params[:logo]) ::Settings::General.original_logo = logo_uploader.url - # An SVG will not be resized, hence we apply the OR statements below to populate SETTINGS consistently. - ::Settings::General.resized_logo = logo_uploader.resized_logo.url || logo_uploader.url + ::Settings::General.resized_logo = logo_uploader.resized_logo.url end end current_user.update!( diff --git a/app/uploaders/base_uploader.rb b/app/uploaders/base_uploader.rb index cc762694b..52e2e7674 100644 --- a/app/uploaders/base_uploader.rb +++ b/app/uploaders/base_uploader.rb @@ -26,9 +26,6 @@ class BaseUploader < CarrierWave::Uploader::Base # strip EXIF (and GPS) data def strip_exif - # svg's do not contain exif or gps data - return if file.content_type.include?("svg") - manipulate! do |image| image.strip unless image.frames.count > FRAME_STRIP_MAX image = yield(image) if block_given? diff --git a/app/uploaders/logo_uploader.rb b/app/uploaders/logo_uploader.rb index 754190a69..2ee5ff33a 100644 --- a/app/uploaders/logo_uploader.rb +++ b/app/uploaders/logo_uploader.rb @@ -1,9 +1,9 @@ class LogoUploader < BaseUploader MAX_FILE_SIZE = 3.megabytes STORE_DIRECTORY = "uploads/logos/".freeze - EXTENSION_ALLOWLIST = %w[svg png jpg jpeg jpe].freeze - IMAGE_TYPE_ALLOWLIST = %i[svg png jpg jpeg jpe].freeze - CONTENT_TYPE_ALLOWLIST = %w[image/svg+xml image/png image/jpg image/jpeg].freeze + EXTENSION_ALLOWLIST = %w[png jpg jpeg jpe].freeze + IMAGE_TYPE_ALLOWLIST = %i[png jpg jpeg jpe].freeze + CONTENT_TYPE_ALLOWLIST = %w[image/png image/jpg image/jpeg].freeze def store_dir STORE_DIRECTORY @@ -31,7 +31,7 @@ class LogoUploader < BaseUploader "original_logo_#{random_string}.#{file.extension}" if original_filename end - version :resized_logo, if: :not_svg? do + version :resized_logo do process resize_to_limit: [nil, 80] def full_filename(_for_file = file) "resized_logo_#{random_string}.#{file.extension}" if original_filename @@ -43,8 +43,4 @@ class LogoUploader < BaseUploader def random_string SecureRandom.alphanumeric(20) end - - def not_svg?(file) - file.content_type.exclude?("svg") - end end diff --git a/app/views/admin/creator_settings/_form.html.erb b/app/views/admin/creator_settings/_form.html.erb index 5cf1bb641..c5ef5ac1b 100644 --- a/app/views/admin/creator_settings/_form.html.erb +++ b/app/views/admin/creator_settings/_form.html.erb @@ -11,7 +11,7 @@ <%= label_tag :logo, class: "crayons-field__label" do %> Logo -

Ideally SVG, but PNG or JPEG will work, too.

+

You can upload a PNG or JPEG image.

<% end %>
<%= file_field_tag :logo, accept: @logo_allowed_types.to_s, data: { "max-file-size-mb": @max_file_size.to_s, action: "change->creator-settings#previewLogo" }, aria: { describedby: "logo-subtitle" } %> diff --git a/spec/uploaders/logo_uploader_spec.rb b/spec/uploaders/logo_uploader_spec.rb index 374efa051..73ba1b99f 100644 --- a/spec/uploaders/logo_uploader_spec.rb +++ b/spec/uploaders/logo_uploader_spec.rb @@ -32,7 +32,7 @@ describe LogoUploader, type: :uploader do describe "formats" do it "permits a set of extensions" do - expect(uploader.extension_allowlist).to eq(%w[svg png jpg jpeg jpe]) + expect(uploader.extension_allowlist).to eq(%w[png jpg jpeg jpe]) end it "permits jpegs" do @@ -45,9 +45,8 @@ describe LogoUploader, type: :uploader do expect(uploader).to be_format("png") end - it "permits svgs" do - uploader.store!(image_svg) - expect(uploader).to be_format("svg") + it "rejects unsupported formats like SVG" do + expect { uploader.store!(image_svg) }.to raise_error(CarrierWave::IntegrityError) end it "rejects unsupported formats like webp" do