FIX: Edge case with anchor tag in `InlineUploads`.
This commit is contained in:
parent
5bc92296be
commit
9a25b0d614
|
@ -228,7 +228,7 @@ class InlineUploads
|
|||
|
||||
spaces_before =
|
||||
if after_html_tag && !match[0].end_with?("/>")
|
||||
(match[3].present? ? match[3] : " ")
|
||||
(match[3].length > 0 ? match[3] : " ")
|
||||
else
|
||||
""
|
||||
end
|
||||
|
|
|
@ -56,6 +56,26 @@ describe Jobs::PullHotlinkedImages do
|
|||
expect(post.reload.raw).to eq("![](#{Upload.last.short_url})")
|
||||
end
|
||||
|
||||
it 'replaces images in an anchor tag with weird indentation' do
|
||||
post = Fabricate(:post, raw: <<~RAW)
|
||||
<a href="https://somelink.com">
|
||||
<img alt="somelink" src="#{image_url}" />
|
||||
</a>
|
||||
RAW
|
||||
|
||||
expect do
|
||||
Jobs::PullHotlinkedImages.new.execute(post_id: post.id)
|
||||
end.to change { Upload.count }.by(1)
|
||||
|
||||
expect(post.reload.raw).to eq(<<~RAW.chomp)
|
||||
<a href="https://somelink.com">
|
||||
|
||||
![somelink](#{post.uploads.last.short_url})
|
||||
|
||||
</a>
|
||||
RAW
|
||||
end
|
||||
|
||||
it 'replaces images without protocol' do
|
||||
url = image_url.sub(/^https?\:/, '')
|
||||
post = Fabricate(:post, raw: "<img alt='test' src='#{url}'>")
|
||||
|
|
|
@ -309,6 +309,11 @@ RSpec.describe InlineUploads do
|
|||
<img src="#{upload.url}" alt="test" width="500" height="500">
|
||||
</a>
|
||||
|
||||
<h1></h1>
|
||||
<a href="http://somelink.com">
|
||||
<img src="#{upload2.url}" alt="test" width="500" height="500">
|
||||
</a>
|
||||
|
||||
<p>
|
||||
<img src="#{upload2.url}" alt="test">
|
||||
</p>
|
||||
|
@ -337,6 +342,13 @@ RSpec.describe InlineUploads do
|
|||
|
||||
</a>
|
||||
|
||||
<h1></h1>
|
||||
<a href="http://somelink.com">
|
||||
|
||||
![test|500x500](#{upload2.short_url})
|
||||
|
||||
</a>
|
||||
|
||||
<p>
|
||||
|
||||
![test](#{upload2.short_url})
|
||||
|
|
Loading…
Reference in New Issue