diff --git a/lib/discourse.rb b/lib/discourse.rb index 7a305879b50..3a29209a3b3 100644 --- a/lib/discourse.rb +++ b/lib/discourse.rb @@ -228,6 +228,8 @@ module Discourse return Rails.application.routes.recognize_path(path) end + nil + rescue ActionController::RoutingError nil end diff --git a/lib/inline_oneboxer.rb b/lib/inline_oneboxer.rb index 7b726d07613..89903e615b7 100644 --- a/lib/inline_oneboxer.rb +++ b/lib/inline_oneboxer.rb @@ -22,8 +22,7 @@ class InlineOneboxer if route = Discourse.route_for(url) if route[:controller] == "topics" && route[:action] == "show" && - - topic = Topic.where(id: route[:topic_id].to_i).first + topic = (Topic.where(id: route[:topic_id].to_i).first rescue nil) # Only public topics if Guardian.new.can_see?(topic) diff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rb index bade562d33a..60f58037983 100644 --- a/spec/components/email/receiver_spec.rb +++ b/spec/components/email/receiver_spec.rb @@ -498,7 +498,7 @@ describe Email::Receiver do it "adds the 'elided' part of the original message when always_show_trimmed_content is enabled" do SiteSetting.always_show_trimmed_content = true - user = Fabricate(:user, email: "existing@bar.com", trust_level: SiteSetting.email_in_min_trust) + Fabricate(:user, email: "existing@bar.com", trust_level: SiteSetting.email_in_min_trust) expect { process(:forwarded_email_to_category) }.to change{Topic.count}.by(1) # Topic created new_post, = Post.last diff --git a/spec/components/inline_oneboxer_spec.rb b/spec/components/inline_oneboxer_spec.rb index 817c5020cdd..d923f8807ab 100644 --- a/spec/components/inline_oneboxer_spec.rb +++ b/spec/components/inline_oneboxer_spec.rb @@ -48,7 +48,13 @@ describe InlineOneboxer do expect(onebox[:url]).to eq(topic.url) expect(onebox[:title]).to eq(topic.title) end + + it "returns nothing for unknown links" do + expect(InlineOneboxer.lookup(nil)).to be_nil + expect(InlineOneboxer.lookup("/test")).to be_nil + end end + end