mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:12:45 +08:00
Use FinalDestination
to ensure public redirects for onebox
This commit is contained in:
parent
9edc490d3f
commit
4c690f7089
|
@ -1,5 +1,6 @@
|
|||
require_dependency 'twitter_api'
|
||||
|
||||
Onebox.options = {
|
||||
twitter_client: TwitterApi
|
||||
twitter_client: TwitterApi,
|
||||
redirect_limit: 1
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
require_dependency "#{Rails.root}/lib/onebox/discourse_onebox_sanitize_config"
|
||||
require_dependency "onebox/discourse_onebox_sanitize_config"
|
||||
require_dependency 'final_destination'
|
||||
|
||||
Dir["#{Rails.root}/lib/onebox/engine/*_onebox.rb"].sort.each { |f| require f }
|
||||
|
||||
module Oneboxer
|
||||
|
@ -140,8 +142,9 @@ module Oneboxer
|
|||
end
|
||||
|
||||
def self.onebox_raw(url)
|
||||
|
||||
Rails.cache.fetch(onebox_cache_key(url), expires_in: 1.day) do
|
||||
uri = URI(url) rescue nil
|
||||
uri = FinalDestination.new(url).resolve
|
||||
return blank_onebox if uri.blank? || SiteSetting.onebox_domains_blacklist.include?(uri.hostname)
|
||||
options = { cache: {}, max_width: 695, sanitize_config: Sanitize::Config::DISCOURSE_ONEBOX }
|
||||
r = Onebox.preview(url, options)
|
||||
|
|
|
@ -19,8 +19,11 @@ describe FinalDestination do
|
|||
end
|
||||
|
||||
before do
|
||||
FinalDestination.stubs(:lookup_ip) do |host|
|
||||
end
|
||||
WebMock.reset!
|
||||
end
|
||||
|
||||
after do
|
||||
WebMock.reset!
|
||||
end
|
||||
|
||||
let(:doc_response) do
|
||||
|
|
Loading…
Reference in New Issue
Block a user