FIX: Check that the node has a src attr when getting size (#19696)
This commit is contained in:
parent
b4adb806e5
commit
c2e18c41a3
|
@ -149,7 +149,7 @@ module CookedProcessorMixin
|
||||||
return unless image_sizes.present?
|
return unless image_sizes.present?
|
||||||
image_sizes.each do |image_size|
|
image_sizes.each do |image_size|
|
||||||
url, size = image_size[0], image_size[1]
|
url, size = image_size[0], image_size[1]
|
||||||
if url && url.include?(src) &&
|
if url && src && url.include?(src) &&
|
||||||
size && size["width"].to_i > 0 && size["height"].to_i > 0
|
size && size["width"].to_i > 0 && size["height"].to_i > 0
|
||||||
return [size["width"], size["height"]]
|
return [size["width"], size["height"]]
|
||||||
end
|
end
|
||||||
|
|
|
@ -870,10 +870,17 @@ RSpec.describe CookedPostProcessor do
|
||||||
let(:post) { build(:post) }
|
let(:post) { build(:post) }
|
||||||
let(:cpp) { CookedPostProcessor.new(post) }
|
let(:cpp) { CookedPostProcessor.new(post) }
|
||||||
|
|
||||||
|
let(:image_sizes) do
|
||||||
|
{ "http://my.discourse.org/image.png" => { "width" => 111, "height" => 222 } }
|
||||||
|
end
|
||||||
|
|
||||||
it "returns the size" do
|
it "returns the size" do
|
||||||
image_sizes = { "http://my.discourse.org/image.png" => { "width" => 111, "height" => 222 } }
|
|
||||||
expect(cpp.get_size_from_image_sizes("/image.png", image_sizes)).to eq([111, 222])
|
expect(cpp.get_size_from_image_sizes("/image.png", image_sizes)).to eq([111, 222])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns nil whe img node has no src" do
|
||||||
|
expect(cpp.get_size_from_image_sizes(nil, image_sizes)).to eq(nil)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#get_size" do
|
describe "#get_size" do
|
||||||
|
|
Loading…
Reference in New Issue