FIX: user and group mentions in subfolder installs

FIX: user and group mentions in subfolder installs

diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb
index 249196f..bad230f 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 1e0cfe9..1490e38 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])

GitHub sha: 421d47da

This commit has been mentioned on Discourse Meta. There might be relevant details there: