Skip to content

Commit

Permalink
FIX: Replace onebox markdown when pulling hotlinked image (#17328)
Browse files Browse the repository at this point in the history
If an image is oneboxed directly, then we should replace the onebox URL with a markdown image tag. This ensures that the wrapper link points to the downloaded version rather than the original.

This regressed in bf6f829
  • Loading branch information
davidtaylorhq committed Jul 5, 2022
1 parent 4730858 commit 78e0364
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/services/inline_uploads.rb
Expand Up @@ -245,6 +245,14 @@ def self.replace_hotlinked_image_urls(raw:, &blk)
# Markdown inline - ![alt](http://... "image title")
InlineUploads.match_md_inline_img(raw, external_src: true, &replace)

raw.gsub!(/^(https?:\/\/\S+)(\s?)$/) do |match|
if upload = blk.call(match)
"![](#{upload.short_url})"
else
match
end
end

raw
end

Expand Down
3 changes: 3 additions & 0 deletions spec/jobs/pull_hotlinked_images_spec.rb
Expand Up @@ -350,6 +350,7 @@
before do
stub_request(:head, url)
stub_request(:get, url).to_return(body: '')
stub_request(:head, image_url)

stub_request(:get, api_url).to_return(body: "{
\"query\": {
Expand Down Expand Up @@ -399,6 +400,7 @@
#{url}
<img src='#{broken_image_url}'>
<a href='#{url}'><img src='#{large_image_url}'></a>
#{image_url}
MD
stub_image_size

Expand All @@ -413,6 +415,7 @@
https://commons.wikimedia.org/wiki/File:Brisbane_May_2013201.jpg
<img src='#{broken_image_url}'>
<a href='#{url}'><img src='#{large_image_url}'></a>
![](upload://z2QSs1KJWoj51uYhDjb6ifCzxH6.gif)
MD

expect(post.cooked).to match(/<p><img src=.*\/uploads/)
Expand Down

1 comment on commit 78e0364

@discoursebot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/oneboxed-image-links-do-not-update-after-being-downloaded-to-local/228612/19

Please sign in to comment.