Skip to content

A platform for community discussion. Free, open, simple.

FIX: user and group mentions in subfolder installs

Penar Musaraj421d47da1ed6
diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb
index 249196fcd13..bad230f57d6 100644
--- a/lib/pretty_text.rb
+++ b/lib/pretty_text.rb
@@ -440,10 +440,10 @@ module PrettyText
case type
when USER_TYPE
- element['href'] = "/u/#{name}"
+ element['href'] = "#{Discourse::base_uri}/u/#{name}"
when GROUP_TYPE
element['class'] = 'mention-group'
- element['href'] = "/groups/#{name}"
+ element['href'] = "#{Discourse::base_uri}/groups/#{name}"
end
end
end
diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb
index 1e0cfe9c73c..1490e38b3ac 100644
--- a/spec/components/pretty_text_spec.rb
+++ b/spec/components/pretty_text_spec.rb
@@ -265,6 +265,23 @@ describe PrettyText do
end
end
+ context 'subfolder' do
+ before do
+ GlobalSetting.stubs(:relative_url_root).returns('/forum')
+ Discourse.stubs(:base_uri).returns("/forum")
+ end
+
+ it "handles user and group mentions correctly" do
+ Fabricate(:user, username: 'user1')
+ Fabricate(:group, name: 'groupA', mentionable_level: Group::ALIAS_LEVELS[:everyone])
+
+ input = 'hi there @user1 and @groupA'
+ expected = '<p>hi there <a class="mention" href="/forum/u/user1">@user1</a> and <a class="mention-group" href="/forum/groups/groupa">@groupA</a></p>'
+
+ expect(PrettyText.cook(input)).to eq(expected)
+ end
+ end
+
it "does not create mention for a non mentionable group" do
group = Fabricate(:group, mentionable_level: Group::ALIAS_LEVELS[:nobody])