mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:12:45 +08:00
FIX: preserve github fragment URL
This commit is contained in:
parent
cae5ba7356
commit
1ab91f0474
|
@ -34,6 +34,7 @@ class FinalDestination
|
|||
|
||||
@opts = opts || {}
|
||||
@force_get_hosts = @opts[:force_get_hosts] || []
|
||||
@preserve_fragment_url_hosts = @opts[:preserve_fragment_url_hosts] || []
|
||||
@opts[:max_redirects] ||= 5
|
||||
@opts[:lookup_ip] ||= lambda { |host| FinalDestination.lookup_ip(host) }
|
||||
|
||||
|
@ -59,6 +60,7 @@ class FinalDestination
|
|||
@limited_ips = []
|
||||
@verbose = @opts[:verbose] || false
|
||||
@timeout = @opts[:timeout] || nil
|
||||
@preserve_fragment_url = @preserve_fragment_url_hosts.any? { |host| hostname_matches?(host) }
|
||||
end
|
||||
|
||||
def self.connection_timeout
|
||||
|
@ -210,6 +212,7 @@ class FinalDestination
|
|||
|
||||
if location
|
||||
old_port = @uri.port
|
||||
location = "#{location}##{@uri.fragment}" if @preserve_fragment_url && @uri.fragment.present?
|
||||
location = "#{@uri.scheme}://#{@uri.host}#{location}" if location[0] == "/"
|
||||
@uri = uri(location)
|
||||
@limit -= 1
|
||||
|
|
|
@ -259,9 +259,13 @@ module Oneboxer
|
|||
SiteSetting.onebox_domains_blacklist.split("|")
|
||||
end
|
||||
|
||||
def self.preserve_fragment_url_hosts
|
||||
['http://github.com']
|
||||
end
|
||||
|
||||
def self.external_onebox(url)
|
||||
Rails.cache.fetch(onebox_cache_key(url), expires_in: 1.day) do
|
||||
fd = FinalDestination.new(url, ignore_redirects: ignore_redirects, ignore_hostnames: blacklisted_domains, force_get_hosts: force_get_hosts)
|
||||
fd = FinalDestination.new(url, ignore_redirects: ignore_redirects, ignore_hostnames: blacklisted_domains, force_get_hosts: force_get_hosts, preserve_fragment_url_hosts: preserve_fragment_url_hosts)
|
||||
uri = fd.resolve
|
||||
return blank_onebox if uri.blank? || blacklisted_domains.map { |hostname| uri.hostname.match?(hostname) }.any?
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@ describe FinalDestination do
|
|||
|
||||
force_get_hosts: ['https://force.get.com'],
|
||||
|
||||
preserve_fragment_url_hosts: ['https://eviltrout.com'],
|
||||
|
||||
# avoid IP lookups in test
|
||||
lookup_ip: lambda do |host|
|
||||
case host
|
||||
|
@ -266,6 +268,18 @@ describe FinalDestination do
|
|||
expect(final.status).to eq(:resolved)
|
||||
expect(final.cookie).to eq("bar=1; baz=2; foo=219ffwef9w0f")
|
||||
end
|
||||
|
||||
it "persists fragment url" do
|
||||
origin_url = "https://eviltrout.com/origin/lib/code/foobar.rb"
|
||||
upstream_url = "https://eviltrout.com/upstream/lib/code/foobar.rb"
|
||||
|
||||
redirect_response(origin_url, upstream_url)
|
||||
stub_request(:head, upstream_url).to_return(doc_response)
|
||||
|
||||
final = FinalDestination.new("#{origin_url}#L154-L205", opts)
|
||||
expect(final.resolve.to_s).to eq("#{upstream_url}#L154-L205")
|
||||
expect(final.status).to eq(:resolved)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.get' do
|
||||
|
|
Loading…
Reference in New Issue
Block a user