A platform for community discussion. Free, open, simple.
FIX: prevents malformed href to crash TopicEmbed (#12910)
Joffrey JAFFEUXed818a4a19f4
diff --git a/app/models/topic_embed.rb b/app/models/topic_embed.rbindex e86a5bd1fa5..d3ed0f1a311 100644--- a/app/models/topic_embed.rb+++ b/app/models/topic_embed.rb@@ -165,7 +165,7 @@ class TopicEmbed < ActiveRecord::Baseuri.host = original_uri.hostnode[url_param] = uri.to_send- rescue URI::Error+ rescue URI::Error, Addressable::URI::InvalidURIError# If there is a mistyped URL, just do nothingendenddiff --git a/spec/models/topic_embed_spec.rb b/spec/models/topic_embed_spec.rbindex 9cf293a9c83..d73135a333a 100644--- a/spec/models/topic_embed_spec.rb+++ b/spec/models/topic_embed_spec.rb@@ -343,6 +343,22 @@ describe TopicEmbed doexpect(response.body).to have_tag('a', with: { href: 'mailto:[email protected]' })endend++ 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+ endenddescribe '.absolutize_urls' do