From 48e3d5b40948515471534cd1606f74a059408c11 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Fri, 29 Sep 2023 09:55:51 +0100 Subject: [PATCH] DEV: Add failing test for pull-hotlinked codeblocks (#23682) If a codeblock contains **exactly** the same markdown as an image which has been retrieved by the 'pull hotlinked' job, then it will be replaced with the new URL. This commit adds failing (skipped) tests for this issue. --- spec/jobs/pull_hotlinked_images_spec.rb | 17 +++++++++++++++++ spec/services/inline_uploads_spec.rb | 12 ++++++++++++ 2 files changed, 29 insertions(+) diff --git a/spec/jobs/pull_hotlinked_images_spec.rb b/spec/jobs/pull_hotlinked_images_spec.rb index e722cd35e99..cbabf01eab1 100644 --- a/spec/jobs/pull_hotlinked_images_spec.rb +++ b/spec/jobs/pull_hotlinked_images_spec.rb @@ -183,6 +183,23 @@ RSpec.describe Jobs::PullHotlinkedImages do expect(post.reload.raw).to eq("[Images](#{url})\n![](#{Upload.last.short_url})") end + it "does not replace images in code blocks", skip: "Known issue" do + post = Fabricate(:post, raw: <<~RAW) + ![realimage](#{image_url}) + `![codeblockimage](#{image_url})` + RAW + stub_image_size + + expect do Jobs::PullHotlinkedImages.new.execute(post_id: post.id) end.to change { + Upload.count + }.by(1) + + expect(post.reload.raw).to eq(<<~RAW) + ![realimage](#{Upload.last.short_url}) + `![codeblockimage](#{image_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 3b564b0a95b..0afc8dd9699 100644 --- a/spec/services/inline_uploads_spec.rb +++ b/spec/services/inline_uploads_spec.rb @@ -385,6 +385,18 @@ RSpec.describe InlineUploads do MD end + it "should not replace identical markdown in code blocks", skip: "Known issue" do + md = <<~MD + `![image|690x290](#{upload.url})` + ![image|690x290](#{upload.url}) + MD + + expect(InlineUploads.process(md)).to eq(<<~MD) + `![image|690x290](#{upload.url})` + ![image|690x290](#{upload.short_url}) + MD + end + it "should not be affected by an emoji" do CustomEmoji.create!(name: "test", upload: upload3) Emoji.clear_cache