BUGFIX: make sure we do not try to pull images from the CDN

This commit is contained in:
Régis Hanol 2014-05-07 19:49:16 +02:00
parent 21e8ae0eca
commit 4b9acd6806
2 changed files with 16 additions and 4 deletions

View File

@ -94,9 +94,21 @@ module Jobs
end end
def is_valid_image_url(src) def is_valid_image_url(src)
src.present? && # make sure we actually have a url
!Discourse.store.has_been_uploaded?(src) && return false unless src.present?
!src.start_with?(Discourse.asset_host || Discourse.base_url_no_prefix) && # we don't want to pull uploaded images
return false if Discourse.store.has_been_uploaded?(src)
# parse the src
begin
uri = URI.parse(src)
rescue URI::InvalidURIError
return false
end
# we don't want to pull images hosted on the CDN (if we use one)
return false if Discourse.asset_host.present? && URI.parse(Discourse.asset_host).hostname == uri.hostname
# we don't want to pull images hosted on the main domain
return false if URI.parse(Discourse.base_url_no_prefix).hostname == uri.hostname
# check the domains blacklist
SiteSetting.should_download_images?(src) SiteSetting.should_download_images?(src)
end end

View File

@ -75,8 +75,8 @@ class SiteSetting < ActiveRecord::Base
def self.should_download_images?(src) def self.should_download_images?(src)
setting = disabled_image_download_domains setting = disabled_image_download_domains
return true unless setting.present? return true unless setting.present?
host = URI.parse(src).host
host = URI.parse(src).host
return !(setting.split('|').include?(host)) return !(setting.split('|').include?(host))
rescue URI::InvalidURIError rescue URI::InvalidURIError
return true return true