A platform for community discussion. Free, open, simple.
FIX: Change max_image_megapixels logic (#25625)
Martin Brennancf4d92f686b5
diff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 13c944df02b..829b4e1efc4 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -4345,7 +4345,7 @@ en:images:too_large: "Sorry, the image you are trying to upload is too big (maximum size is %{max_size_kb}KB), please resize it and try again."too_large_humanized: "Sorry, the image you are trying to upload is too big (maximum size is %{max_size}), please resize it and try again."- larger_than_x_megapixels: "Sorry, the image you are trying to upload is too large (maximum dimension is %{max_image_megapixels}-megapixels), please resize it and try again."+ larger_than_x_megapixels: "Sorry, the image you are trying to upload is too large (maximum dimension is %{max_image_megapixels} megapixels), please resize it and try again."size_not_found: "Sorry, but we couldn't determine the size of the image. Maybe your image is corrupted?"placeholders:too_large: "(image larger than %{max_size_kb}KB)"diff --git a/lib/upload_creator.rb b/lib/upload_creator.rbindex 54615a1101f..c992c285c12 100644--- a/lib/upload_creator.rb+++ b/lib/upload_creator.rb@@ -301,12 +301,12 @@ class UploadCreator@upload.errors.add(:base, I18n.t("upload.empty"))elsif pixels == 0 && @image_info.type.to_s != "svg"@upload.errors.add(:base, I18n.t("upload.images.size_not_found"))- elsif max_image_pixels > 0 && pixels >= max_image_pixels * 2+ elsif max_image_pixels > 0 && pixels >= max_image_pixels@upload.errors.add(:base,I18n.t("upload.images.larger_than_x_megapixels",- max_image_megapixels: SiteSetting.max_image_megapixels * 2,+ max_image_megapixels: SiteSetting.max_image_megapixels,),)enddiff --git a/spec/models/upload_spec.rb b/spec/models/upload_spec.rbindex b955571fa0a..0fbd19ee48b 100644--- a/spec/models/upload_spec.rb+++ b/spec/models/upload_spec.rb@@ -74,6 +74,7 @@ RSpec.describe Upload doendit "can reconstruct dimensions on demand" do+ SiteSetting.max_image_megapixels = 85upload = UploadCreator.new(huge_image, "image.png").create_for(user_id)upload.update_columns(width: nil, height: nil, thumbnail_width: nil, thumbnail_height: nil)@@ -93,6 +94,7 @@ RSpec.describe Upload doendit "dimension calculation returns nil on missing image" do+ SiteSetting.max_image_megapixels = 85upload = UploadCreator.new(huge_image, "image.png").create_for(user_id)upload.update_columns(width: nil, height: nil, thumbnail_width: nil, thumbnail_height: nil)@@ -107,7 +109,7 @@ RSpec.describe Upload doupload = UploadCreator.new(huge_image, "image.png").create_for(user_id)expect(upload.persisted?).to eq(false)expect(upload.errors.messages[:base].first).to eq(- I18n.t("upload.images.larger_than_x_megapixels", max_image_megapixels: 20),+ I18n.t("upload.images.larger_than_x_megapixels", max_image_megapixels: 10),)end