mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08: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
2 changed files with 20 additions and 1 deletions
|
@ -245,7 +245,7 @@ class InlineUploads
|
||||||
# Markdown inline - 
|
# Markdown inline - 
|
||||||
InlineUploads.match_md_inline_img(raw, external_src: true, &replace)
|
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)
|
if upload = blk.call(match)
|
||||||
""
|
""
|
||||||
else
|
else
|
||||||
|
|
|
@ -423,6 +423,25 @@ describe Jobs::PullHotlinkedImages do
|
||||||
expect(post.cooked).to match(/<span class="broken-image/)
|
expect(post.cooked).to match(/<span class="broken-image/)
|
||||||
expect(post.cooked).to match(/<div class="large-image-placeholder">/)
|
expect(post.cooked).to match(/<div class="large-image-placeholder">/)
|
||||||
end
|
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:
|
||||||
|

|
||||||
|
MD
|
||||||
|
|
||||||
|
expect(post.cooked).to match(/<img src=.*\/uploads/)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue