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.
This commit is contained in:
David Taylor 2023-09-29 09:55:51 +01:00 committed by GitHub
parent 408579e6b2
commit 48e3d5b409
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View File

@ -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: "<img alt='test' src='#{url}'>")

View File

@ -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