diff --git a/app/models/topic_link.rb b/app/models/topic_link.rb index e9a178cb8ef..b4b5caf236a 100644 --- a/app/models/topic_link.rb +++ b/app/models/topic_link.rb @@ -144,7 +144,6 @@ SQL url = "#{Discourse.base_url_no_prefix}#{topic.relative_url}" url << "/#{post_number}" if post_number.to_i > 1 end - end # Skip linking to ourselves @@ -182,7 +181,7 @@ SQL if topic_id.present? topic = Topic.find_by(id: topic_id) - if topic && post.topic && post.topic.archetype != 'private_message' && topic.archetype != 'private_message' + if topic && post.topic && topic.archetype != 'private_message' && post.topic.archetype != 'private_message' && post.topic.visible? prefix = Discourse.base_url_no_prefix reflected_url = "#{prefix}#{post.topic.relative_url(post.post_number)}" tl = TopicLink.find_by(topic_id: topic_id, diff --git a/spec/models/topic_link_spec.rb b/spec/models/topic_link_spec.rb index c42371a8bfb..9601a996aa7 100644 --- a/spec/models/topic_link_spec.rb +++ b/spec/models/topic_link_spec.rb @@ -251,6 +251,21 @@ http://b.com/#{'a' * 500} end + describe 'internal link from unlisted topic' do + it 'works' do + unlisted_topic = Fabricate(:topic, user: user, visible: false) + url = "http://#{test_uri.host}/t/topic-slug/#{topic.id}" + + unlisted_topic.posts.create(user: user, raw: 'initial post') + linked_post = unlisted_topic.posts.create(user: user, raw: "Link to another topic: #{url}") + + TopicLink.extract_from(linked_post) + + expect(topic.topic_links.first).to eq(nil) + expect(unlisted_topic.topic_links.first).not_to eq(nil) + end + end + describe 'internal link with non-standard port' do it 'includes the non standard port if present' do other_topic = Fabricate(:topic, user: user)