diff --git a/app/services/inline_uploads.rb b/app/services/inline_uploads.rb index 4ae95e8ce56..6ac8ed5dbbf 100644 --- a/app/services/inline_uploads.rb +++ b/app/services/inline_uploads.rb @@ -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 diff --git a/spec/jobs/pull_hotlinked_images_spec.rb b/spec/jobs/pull_hotlinked_images_spec.rb index 17a11889b44..a1548fca3ea 100644 --- a/spec/jobs/pull_hotlinked_images_spec.rb +++ b/spec/jobs/pull_hotlinked_images_spec.rb @@ -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) + + somelink + + 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) + + + ![somelink](#{post.uploads.last.short_url}) + + + RAW + end + it 'replaces images without protocol' do url = image_url.sub(/^https?\:/, '') post = Fabricate(:post, raw: "test") diff --git a/spec/services/inline_uploads_spec.rb b/spec/services/inline_uploads_spec.rb index ef7f48d7c73..d54666f1831 100644 --- a/spec/services/inline_uploads_spec.rb +++ b/spec/services/inline_uploads_spec.rb @@ -309,6 +309,11 @@ RSpec.describe InlineUploads do test +

+ + test + +

test

@@ -337,6 +342,13 @@ RSpec.describe InlineUploads do +

+ + + ![test|500x500](#{upload2.short_url}) + + +

![test](#{upload2.short_url})