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
def is_valid_image_url(src)
src.present? &&
!Discourse.store.has_been_uploaded?(src) &&
!src.start_with?(Discourse.asset_host || Discourse.base_url_no_prefix) &&
# make sure we actually have a url
return false unless src.present?
# 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)
end

View File

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