mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
FIX: Gracefully handle inline images in emails (#12855)
This commit is contained in:
parent
849b786378
commit
e6329d3007
|
@ -1124,8 +1124,8 @@ module Email
|
||||||
raw = raw.sub(match, replacement)
|
raw = raw.sub(match, replacement)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elsif raw[/\[image:.*?\d+[^\]]*\]/i]
|
elsif raw[/\[image:[^\]]*\]/i]
|
||||||
raw.sub!(/\[image:.*?\d+[^\]]*\]/i, UploadMarkdown.new(upload).to_markdown)
|
raw.sub!(/\[image:[^\]]*\]/i, UploadMarkdown.new(upload).to_markdown)
|
||||||
else
|
else
|
||||||
raw << "\n\n#{UploadMarkdown.new(upload).to_markdown}\n\n"
|
raw << "\n\n#{UploadMarkdown.new(upload).to_markdown}\n\n"
|
||||||
end
|
end
|
||||||
|
|
|
@ -585,6 +585,19 @@ describe Email::Receiver do
|
||||||
MD
|
MD
|
||||||
end
|
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
|
it "supports attached images in signature" do
|
||||||
SiteSetting.incoming_email_prefer_html = true
|
SiteSetting.incoming_email_prefer_html = true
|
||||||
SiteSetting.always_show_trimmed_content = true
|
SiteSetting.always_show_trimmed_content = true
|
||||||
|
|
26
spec/fixtures/emails/inline_image_2.eml
vendored
Normal file
26
spec/fixtures/emails/inline_image_2.eml
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user