FIX: Ensure pull-hotlinked can rewrite lone oneboxes (#17354)

Mutating the `raw` variable like this would cause issues upstream, meaning that the modification is not persisted. Instead, we should allocate a new string like the other replacement methods.
This commit is contained in:
David Taylor 2022-07-06 11:46:33 +01:00 committed by GitHub
parent 2e4056d185
commit 2d5d15b4bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -245,7 +245,7 @@ class InlineUploads
# Markdown inline - ![alt](http://... "image title")
InlineUploads.match_md_inline_img(raw, external_src: true, &replace)
raw.gsub!(/^(https?:\/\/\S+)(\s?)$/) do |match|
raw = raw.gsub(/^(https?:\/\/\S+)(\s?)$/) do |match|
if upload = blk.call(match)
"![](#{upload.short_url})"
else

View File

@ -423,6 +423,25 @@ describe Jobs::PullHotlinkedImages do
expect(post.cooked).to match(/<span class="broken-image/)
expect(post.cooked).to match(/<div class="large-image-placeholder">/)
end
it 'rewrites a lone onebox' do
post = Fabricate(:post, raw: <<~MD)
Onebox here:
#{image_url}
MD
stub_image_size
post.rebake!
post.reload
expect(post.raw).to eq(<<~MD.chomp)
Onebox here:
![](upload://z2QSs1KJWoj51uYhDjb6ifCzxH6.gif)
MD
expect(post.cooked).to match(/<img src=.*\/uploads/)
end
end
end