FIX: include 'short_path' as src in each_upload_url method.

FIX: include ‘short_path’ as src in each_upload_url method.

diff --git a/app/models/post.rb b/app/models/post.rb
index c22d5aa..8efcad9 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -918,10 +918,14 @@ class Post < ActiveRecord::Base
         sha1 = Upload.sha1_from_short_url(src)
         yield(src, nil, sha1)
         next
+      elsif src.include?("/uploads/short-url/")
+        sha1 = Upload.sha1_from_short_path(src)
+        yield(src, nil, sha1)
+        next
       end
 
       next if upload_patterns.none? { |pattern| src =~ pattern }
-      next if Rails.configuration.multisite && src.exclude?(current_db) && src.exclude?("short-url")
+      next if Rails.configuration.multisite && src.exclude?(current_db)
 
       src = "#{SiteSetting.force_https ? "https" : "http"}:#{src}" if src.start_with?("//")
       next unless Discourse.store.has_been_uploaded?(src) || (include_local_upload && src =~ /\A\/[^\/]/i)
diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb
index f51c586..9f69f4f 100644
--- a/spec/models/post_spec.rb
+++ b/spec/models/post_spec.rb
@@ -1362,13 +1362,15 @@ describe Post do
 
   describe '#each_upload_url' do
     it "correctly identifies all upload urls" do
+      SiteSetting.authorized_extensions = "*"
       upload1 = Fabricate(:upload)
       upload2 = Fabricate(:upload)
+      upload3 = Fabricate(:video_upload)
 
       set_cdn_url "https://awesome.com/somepath"
 
       post = Fabricate(:post, raw: <<~RAW)
-      A post with image and link upload.
+      A post with image, video and link upload.
 
       ![](#{upload1.short_url})
 
@@ -1376,6 +1378,8 @@ describe Post do
 
       <a href='#{Discourse.base_url}#{upload2.url}'>Link to upload</a>
       ![](http://example.com/external.png)
+
+      #{Discourse.base_url}#{upload3.short_path}
       RAW
 
       urls = []
@@ -1389,13 +1393,15 @@ describe Post do
       expect(urls).to contain_exactly(
         upload1.url,
         "#{GlobalSetting.cdn_url}#{upload1.url}",
-        "#{Discourse.base_url}#{upload2.url}"
+        "#{Discourse.base_url}#{upload2.url}",
+        "#{Discourse.base_url}#{upload3.short_path}"
       )
 
       expect(paths).to contain_exactly(
         upload1.url,
         upload1.url,
-        upload2.url
+        upload2.url,
+        nil
       )
     end

GitHub sha: 301c5a30

2 Likes