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

This commit is contained in:
Vinoth Kannan 2019-09-22 15:32:28 +05:30
parent 7543695744
commit 301c5a303f
2 changed files with 14 additions and 4 deletions

View File

@ -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)

View File

@ -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