mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 09:04:45 +08:00
FIX: prevents malformed href to crash TopicEmbed (#12910)
If the associated page of a remote url passed to `TopicEmber.new(remote_url)` contained a malformed link like: `<a href="(http://foo.bar)">Baz</a>` it would raise an uncaught exception: ``` Job exception: Invalid scheme format: (http ```
This commit is contained in:
@ -165,7 +165,7 @@ class TopicEmbed < ActiveRecord::Base
|
|||||||
uri.host = original_uri.host
|
uri.host = original_uri.host
|
||||||
node[url_param] = uri.to_s
|
node[url_param] = uri.to_s
|
||||||
end
|
end
|
||||||
rescue URI::Error
|
rescue URI::Error, Addressable::URI::InvalidURIError
|
||||||
# If there is a mistyped URL, just do nothing
|
# If there is a mistyped URL, just do nothing
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -343,6 +343,22 @@ describe TopicEmbed do
|
|||||||
expect(response.body).to have_tag('a', with: { href: 'mailto:bar@example.com' })
|
expect(response.body).to have_tag('a', with: { href: 'mailto:bar@example.com' })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "malformed href" do
|
||||||
|
let(:url) { 'http://example.com/foo' }
|
||||||
|
let(:contents) { '<p><a href="(http://foo.bar)">Baz</a></p>' }
|
||||||
|
let!(:file) { StringIO.new }
|
||||||
|
|
||||||
|
before do
|
||||||
|
file.stubs(:read).returns contents
|
||||||
|
TopicEmbed.stubs(:open).returns file
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn’t raise an exception" do
|
||||||
|
stub_request(:head, url)
|
||||||
|
expect { TopicEmbed.find_remote(url) }.not_to raise_error
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.absolutize_urls' do
|
describe '.absolutize_urls' do
|
||||||
|
Reference in New Issue
Block a user