FIX: Gracefully handle inline images in emails (#12855)

This commit is contained in:
Bianca Nenciu 2021-04-29 10:17:33 +03:00 committed by GitHub
parent 849b786378
commit e6329d3007
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

View File

@ -1124,8 +1124,8 @@ module Email
raw = raw.sub(match, replacement)
end
end
elsif raw[/\[image:.*?\d+[^\]]*\]/i]
raw.sub!(/\[image:.*?\d+[^\]]*\]/i, UploadMarkdown.new(upload).to_markdown)
elsif raw[/\[image:[^\]]*\]/i]
raw.sub!(/\[image:[^\]]*\]/i, UploadMarkdown.new(upload).to_markdown)
else
raw << "\n\n#{UploadMarkdown.new(upload).to_markdown}\n\n"
end

View File

@ -585,6 +585,19 @@ describe Email::Receiver do
MD
end
it "gracefully handles malformed images in HTML part" do
expect { process(:inline_image_2) }.to change { topic.posts.count }
post = topic.posts.last
upload = post.uploads.last
expect(post.raw).to eq(<<~MD.chomp)
[image:#{'0' * 5000}
![#{upload.original_filename}|#{upload.width}x#{upload.height}](#{upload.short_url})
MD
end
it "supports attached images in signature" do
SiteSetting.incoming_email_prefer_html = true
SiteSetting.always_show_trimmed_content = true

BIN
spec/fixtures/emails/inline_image_2.eml vendored Normal file

Binary file not shown.