mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
@@ -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?("//")
|
||||
|
||||
Reference in New Issue
Block a user