FIX: include 'short_url' as src if upload url not exist

The URL '/images/transparent.png' will be used in the cooked content if upload record not found. In that case we have to use 'short_url' as image src in 'post.each_upload_url' method.
This commit is contained in:
Vinoth Kannan
2019-09-02 15:11:22 +05:30
parent 08743e8ac0
commit aa012d12dc
2 changed files with 42 additions and 2 deletions

View File

@@ -895,10 +895,27 @@ class Post < ActiveRecord::Base
]
fragments ||= Nokogiri::HTML::fragment(self.cooked)
links = fragments.css("a/@href", "img/@src").map { |media| media.value }.uniq
links = fragments.css("a/@href", "img/@src").map do |media|
src = media.value
next if src.blank?
if src.end_with?("/images/transparent.png") && (parent = media.parent)["data-orig-src"].present?
parent["data-orig-src"]
else
src
end
end.compact.uniq
links.each do |src|
next if src.blank? || upload_patterns.none? { |pattern| src.split("?")[0] =~ pattern }
src = src.split("?")[0]
if src.start_with?("upload://")
sha1 = Upload.sha1_from_short_url(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")
src = "#{SiteSetting.force_https ? "https" : "http"}:#{src}" if src.start_with?("//")