A platform for community discussion. Free, open, simple.
FIX: downloaded image URLs incorrectly replaced in post raw. (#9014)
Vinoth Kannan5774107a2d8f
diff --git a/app/jobs/regular/pull_hotlinked_images.rb b/app/jobs/regular/pull_hotlinked_images.rbindex 252c3790523..25703659460 100644--- a/app/jobs/regular/pull_hotlinked_images.rb+++ b/app/jobs/regular/pull_hotlinked_images.rb@@ -95,7 +95,7 @@ module Jobsescaped_src = Regexp.escape(original_src)replace_raw = ->(match, match_src, replacement, _index) {- if src.include?(match_src)+ if remove_scheme(src) == remove_scheme(match_src)replacement =if replacement.include?(InlineUploads::PLACEHOLDER)diff --git a/spec/jobs/pull_hotlinked_images_spec.rb b/spec/jobs/pull_hotlinked_images_spec.rbindex 40406744509..6e3a21ca9a7 100644--- a/spec/jobs/pull_hotlinked_images_spec.rb+++ b/spec/jobs/pull_hotlinked_images_spec.rb@@ -83,6 +83,17 @@ describe Jobs::PullHotlinkedImages doRAWend+ it 'replaces correct image URL' do+ url = image_url.sub("/2e/Longcat1.png", '')+ post = Fabricate(:post, raw: "[Images](#{url})\n")++ expect do+ Jobs::PullHotlinkedImages.new.execute(post_id: post.id)+ end.to change { Upload.count }.by(1)++ expect(post.reload.raw).to eq("[Images](#{url})\n")+ end+it 'replaces images without protocol' dourl = image_url.sub(/^https?\:/, '')post = Fabricate(:post, raw: "<img alt='test' src='#{url}'>")