mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: persist secure image width and height if is given (#10994)
`max-width: 50%; max-height: 400px;` is a good fallback, however, if width and height are given and are smaller than fallback - we should persist that smaller size.
This commit is contained in:
committed by
GitHub
parent
64b0b50ac0
commit
b2481adb40
@@ -212,7 +212,7 @@ describe Email::Styles do
|
||||
fab!(:upload) { Fabricate(:upload, original_filename: 'testimage.png', secure: true, sha1: '123456') }
|
||||
|
||||
def strip_and_inline
|
||||
html = "<a href=\"#{Discourse.base_url}\/secure-media-uploads/original/1X/123456.png\"><img src=\"/secure-media-uploads/original/1X/123456.png\"></a>"
|
||||
html = "<a href=\"#{Discourse.base_url}\/secure-media-uploads/original/1X/123456.png\"><img src=\"/secure-media-uploads/original/1X/123456.png\" width=\"20\" height=\"30\"></a>"
|
||||
|
||||
# strip out the secure media
|
||||
styler = Email::Styles.new(html)
|
||||
@@ -230,6 +230,7 @@ describe Email::Styles do
|
||||
strip_and_inline
|
||||
expect(@frag.to_s).to include("cid:email/test.png")
|
||||
expect(@frag.css('[data-stripped-secure-media]')).not_to be_present
|
||||
expect(@frag.children.attr('style').value).to eq("width: 20px; height: 30px;")
|
||||
end
|
||||
|
||||
it "does not inline anything if the upload cannot be found" do
|
||||
|
||||
@@ -966,12 +966,14 @@ describe PrettyText do
|
||||
it "replaces secure images with a placeholder, keeping the url in an attribute" do
|
||||
url = "/secure-media-uploads/original/1X/testimage.png"
|
||||
html = <<~HTML
|
||||
<img src=\"#{url}\">
|
||||
<img src=\"#{url}\" width=\"20\" height=\"20\">
|
||||
HTML
|
||||
md = PrettyText.format_for_email(html, post)
|
||||
expect(md).not_to include('<img')
|
||||
expect(md).to include("Redacted")
|
||||
expect(md).to include("data-stripped-secure-media=\"#{url}\"")
|
||||
expect(md).to include("data-width=\"20\"")
|
||||
expect(md).to include("data-height=\"20\"")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user