mirror of
https://github.com/discourse/discourse.git
synced 2025-03-25 17:30:09 +08:00
FIX: Okay, add support for hosts that have trailing paths
This commit is contained in:
parent
73f547b019
commit
b02d624503
@ -71,13 +71,15 @@ class SiteSetting < ActiveRecord::Base
|
|||||||
def self.allows_embeddable_host?(host)
|
def self.allows_embeddable_host?(host)
|
||||||
return false if embeddable_hosts.blank?
|
return false if embeddable_hosts.blank?
|
||||||
uri = URI(host) rescue nil
|
uri = URI(host) rescue nil
|
||||||
|
|
||||||
return false unless uri.present?
|
return false unless uri.present?
|
||||||
|
|
||||||
host = uri.host
|
host = uri.host
|
||||||
return false unless host.present?
|
return false unless host.present?
|
||||||
|
|
||||||
!!embeddable_hosts.split("\n").detect {|h| h.sub(/^https?\:\/\//, '') == host }
|
!!embeddable_hosts.split("\n").detect {|h| h.sub(/^https?\:\/\//, '') == host }
|
||||||
|
|
||||||
|
hosts = embeddable_hosts.split("\n").map {|h| (URI(h).host rescue nil) || h }
|
||||||
|
!!hosts.detect {|h| h == host}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.anonymous_homepage
|
def self.anonymous_homepage
|
||||||
|
@ -68,7 +68,7 @@ describe EmbedController do
|
|||||||
|
|
||||||
context "with multiple hosts" do
|
context "with multiple hosts" do
|
||||||
before do
|
before do
|
||||||
SiteSetting.embeddable_hosts = "#{host}\nhttp://discourse.org"
|
SiteSetting.embeddable_hosts = "#{host}\nhttp://discourse.org\nhttps://example.com/1234"
|
||||||
end
|
end
|
||||||
|
|
||||||
context "success" do
|
context "success" do
|
||||||
@ -84,6 +84,12 @@ describe EmbedController do
|
|||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "works with a host with a path" do
|
||||||
|
controller.request.stubs(:referer).returns("https://example.com/some-other-path")
|
||||||
|
get :comments, embed_url: embed_url
|
||||||
|
expect(response).to be_success
|
||||||
|
end
|
||||||
|
|
||||||
it "doesn't work with a made up host" do
|
it "doesn't work with a made up host" do
|
||||||
controller.request.stubs(:referer).returns("http://codinghorror.com/invalid-url")
|
controller.request.stubs(:referer).returns("http://codinghorror.com/invalid-url")
|
||||||
get :comments, embed_url: embed_url
|
get :comments, embed_url: embed_url
|
||||||
|
Loading…
x
Reference in New Issue
Block a user