From 1cae875146109b40a56d7ae5d4132276089c607d Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Thu, 19 Oct 2017 15:26:37 +0200 Subject: [PATCH] FIX: topic link extraction shouldn't fail when the parsed URL has no path --- app/models/topic_link.rb | 2 +- spec/models/topic_link_spec.rb | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/topic_link.rb b/app/models/topic_link.rb index d66e1616f5f..da635aeb998 100644 --- a/app/models/topic_link.rb +++ b/app/models/topic_link.rb @@ -161,7 +161,7 @@ SQL added_urls << url unless TopicLink.exists?(topic_id: post.topic_id, post_id: post.id, url: url) - file_extension = File.extname(parsed.path)[1..10].downcase unless File.extname(parsed.path).empty? + file_extension = File.extname(parsed.path)[1..10].downcase unless parsed.path.nil? || File.extname(parsed.path).empty? begin TopicLink.create!(post_id: post.id, user_id: post.user_id, diff --git a/spec/models/topic_link_spec.rb b/spec/models/topic_link_spec.rb index 40fafa5a03c..bb9408f8081 100644 --- a/spec/models/topic_link_spec.rb +++ b/spec/models/topic_link_spec.rb @@ -230,7 +230,6 @@ http://b.com/#{'a' * 500} end end - end describe 'internal link from pm' do @@ -382,6 +381,11 @@ http://b.com/#{'a' * 500} expect(result).to eq({}) end end + + it "works with invalid link target" do + post = Fabricate(:post, raw: 'http:geturl', user: user, topic: topic, cook_method: Post.cook_methods[:raw_html]) + expect { TopicLink.extract_from(post) }.to_not raise_error + end end end