From 91c89df68abeb945ee4d348ef5365af2001a8492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Tue, 23 Jun 2020 17:18:38 +0200 Subject: [PATCH] FIX: onebox local topic when using slug-less URL When linking to a topic in the same Discourse, we try to onebox the link to show the title and other various information depending on whether it's a "standard" or "inline" onebox. However, we were not properly detecting links to topics that had no slugs (eg. https://meta.discourse.org/t/1234). --- lib/oneboxer.rb | 4 +--- spec/components/oneboxer_spec.rb | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/oneboxer.rb b/lib/oneboxer.rb index d3625f19d8b..eb5067cae95 100644 --- a/lib/oneboxer.rb +++ b/lib/oneboxer.rb @@ -219,9 +219,7 @@ module Oneboxer end end - topic = Topic.find_by(id: route[:topic_id]) - - return unless topic + return unless topic = Topic.find_by(id: route[:id] || route[:topic_id]) return if topic.private_message? if current_category.blank? || current_category.id != topic.category_id diff --git a/spec/components/oneboxer_spec.rb b/spec/components/oneboxer_spec.rb index c5bc2dca861..f1681e5bc2b 100644 --- a/spec/components/oneboxer_spec.rb +++ b/spec/components/oneboxer_spec.rb @@ -69,6 +69,9 @@ describe Oneboxer do expect(onebox).to include(%{data-post="2"}) expect(onebox).to include(PrettyText.avatar_img(replier.avatar_template, "tiny")) + short_url = "#{Discourse.base_uri}/t/#{public_topic.id}" + expect(preview(short_url, user, public_category)).to include(public_topic.title) + onebox = preview(public_moderator_action.url, user, public_category) expect(onebox).to include(public_moderator_action.excerpt) expect(onebox).to include(%{data-post="4"})