mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 03:10:46 -06:00
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:
parent
2e4056d185
commit
2d5d15b4bb
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user