mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Handle addressable error when parsing an invalid URL. (#15836)
Passing in an invalid URL would result in an `Addressable::URI::InvalidURIError` which we were not catching.
This commit is contained in:
parent
5bd55acf83
commit
b7eacaed21
@ -14,13 +14,13 @@ class EmbeddableHost < ActiveRecord::Base
|
|||||||
self.ignored_columns = ["path_whitelist"]
|
self.ignored_columns = ["path_whitelist"]
|
||||||
|
|
||||||
def self.record_for_url(uri)
|
def self.record_for_url(uri)
|
||||||
|
|
||||||
if uri.is_a?(String)
|
if uri.is_a?(String)
|
||||||
uri = begin
|
uri = begin
|
||||||
URI(UrlHelper.escape_uri(uri))
|
URI(UrlHelper.escape_uri(uri))
|
||||||
rescue URI::Error
|
rescue URI::Error, Addressable::URI::InvalidURIError
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return false unless uri.present?
|
return false unless uri.present?
|
||||||
|
|
||||||
host = uri.host
|
host = uri.host
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe EmbeddableHost do
|
describe EmbeddableHost do
|
||||||
|
|
||||||
it "trims http" do
|
it "trims http" do
|
||||||
eh = EmbeddableHost.new(host: 'http://example.com')
|
eh = EmbeddableHost.new(host: 'http://example.com')
|
||||||
expect(eh).to be_valid
|
expect(eh).to be_valid
|
||||||
@ -149,4 +148,16 @@ describe EmbeddableHost do
|
|||||||
expect(SiteSetting.embed_post_limit).to eq(SiteSetting.defaults[:embed_post_limit])
|
expect(SiteSetting.embed_post_limit).to eq(SiteSetting.defaults[:embed_post_limit])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '.record_for_url' do
|
||||||
|
fab!(:embeddable_host) { Fabricate(:embeddable_host) }
|
||||||
|
|
||||||
|
it 'returns the right record if given URL matches host' do
|
||||||
|
expect(EmbeddableHost.record_for_url("https://#{embeddable_host.host}")).to eq(embeddable_host)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns false if URL is malformed' do
|
||||||
|
expect(EmbeddableHost.record_for_url("@@@@@")).to eq(false)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user