diff --git a/app/models/post.rb b/app/models/post.rb
index c579d012ea0..b4edb7b94bb 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -896,16 +896,17 @@ class Post < ActiveRecord::Base
fragments ||= Nokogiri::HTML::fragment(self.cooked)
links = fragments.css("a/@href", "img/@src").map { |media| media.value }.uniq
+ local_store = FileStore::LocalStore.new
links.each do |src|
next if src.blank? || upload_patterns.none? { |pattern| src.split("?")[0] =~ pattern }
next if Rails.configuration.multisite && src.exclude?(current_db) && src.exclude?("short-url")
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)
+ next unless Discourse.store.has_been_uploaded?(src) || (include_local_upload && (src =~ /\A\/[^\/]/i || local_store.has_been_uploaded?(src)))
path = begin
- URI(URI.unescape(src))&.path
+ URI(URI.unescape(src.gsub(GlobalSetting.cdn_url, "")))&.path
rescue URI::Error
end
diff --git a/app/services/inline_uploads.rb b/app/services/inline_uploads.rb
index 989301ebc14..7a3204346e4 100644
--- a/app/services/inline_uploads.rb
+++ b/app/services/inline_uploads.rb
@@ -272,13 +272,17 @@ class InlineUploads
cdn_url = GlobalSetting.cdn_url.sub(/https?:\/\//, "(https?://)")
end
+ db = RailsMultisite::ConnectionManagement.current_db
+
regexps = [
/(upload:\/\/([a-zA-Z0-9]+)[a-zA-Z0-9\.]*)/,
/(\/uploads\/short-url\/([a-zA-Z0-9]+)[a-zA-Z0-9\.]*)/,
/(#{base_url}\/uploads\/short-url\/([a-zA-Z0-9]+)[a-zA-Z0-9\.]*)/,
+ /(\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/,
+ /(#{base_url}\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/,
]
- db = RailsMultisite::ConnectionManagement.current_db
+ regexps << /(#{cdn_url}\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/ if cdn_url
if Discourse.store.external?
if Rails.configuration.multisite
@@ -287,14 +291,7 @@ class InlineUploads
else
regexps << /((https?:)?#{SiteSetting.Upload.s3_base_url}#{UPLOAD_REGEXP_PATTERN})/
regexps << /(#{SiteSetting.Upload.s3_cdn_url}#{UPLOAD_REGEXP_PATTERN})/
- regexps << /(\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/
- regexps << /(#{base_url}\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/
- regexps << /(#{cdn_url}\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/ if cdn_url
end
- else
- regexps << /(\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/
- regexps << /(#{base_url}\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/
- regexps << /(#{cdn_url}\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/ if cdn_url
end
node = node.to_s
diff --git a/spec/services/inline_uploads_spec.rb b/spec/services/inline_uploads_spec.rb
index 93943c0e34e..9a39d93e2c7 100644
--- a/spec/services/inline_uploads_spec.rb
+++ b/spec/services/inline_uploads_spec.rb
@@ -587,8 +587,10 @@ RSpec.describe InlineUploads do
describe "s3 uploads" do
let(:upload) { Fabricate(:upload_s3) }
let(:upload2) { Fabricate(:upload_s3) }
+ let(:upload3) { Fabricate(:upload) }
before do
+ upload3
SiteSetting.enable_s3_uploads = true
SiteSetting.s3_upload_bucket = "s3-upload-bucket"
SiteSetting.s3_access_key_id = "some key"
@@ -636,6 +638,7 @@ RSpec.describe InlineUploads do
+
MD
expect(InlineUploads.process(md)).to eq(<<~MD)
@@ -644,6 +647,7 @@ RSpec.describe InlineUploads do
![some image](#{upload.short_url})
![some image](#{upload2.short_url})
+ ![](#{upload3.short_url})
MD
ensure
Rails.configuration.multisite = false