FIX: Fix mentions for mixed case group names

FIX: Fix mentions for mixed case group names

From afcf149c341d765260b14dd0ff76c43223181334 Mon Sep 17 00:00:00 2001
From: David Taylor <david@taylorhq.com>
Date: Mon, 26 Nov 2018 15:34:56 +0000
Subject: [PATCH] FIX: Fix mentions for mixed case group names


diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb
index 30bb0c0..249196f 100644
--- a/lib/pretty_text.rb
+++ b/lib/pretty_text.rb
@@ -464,9 +464,9 @@ module PrettyText
     (
       SELECT
         :group_type AS type,
-        name
+        lower(name) AS name
       FROM groups
-      WHERE name IN (:names) AND (#{Group.mentionable_sql_clause})
+      WHERE lower(name) IN (:names) AND (#{Group.mentionable_sql_clause})
     )
     SQL
 
diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb
index 36358f5..32c3220 100644
--- a/spec/components/pretty_text_spec.rb
+++ b/spec/components/pretty_text_spec.rb
@@ -225,9 +225,12 @@ describe PrettyText do
         Fabricate(:user, username: username)
       end
 
-      group = Fabricate(:group,
-        mentionable_level: Group::ALIAS_LEVELS[:everyone]
-      )
+      ['Group', 'group2'].each do |name|
+        Fabricate(:group,
+          name: name,
+          mentionable_level: Group::ALIAS_LEVELS[:everyone]
+        )
+      end
 
       [
         [
@@ -235,8 +238,8 @@ describe PrettyText do
           '<p>hi <a class="mention" href="/u/user">@uSer</a>! <a class="mention" href="/u/user2">@user2</a> hi</p>'
         ],
         [
-          "hi\n@user. @#{group.name.capitalize} @somemention",
-          %Q|<p>hi<br>\n<a class="mention" href="/u/user">@user</a>. <a class="mention-group" href="/groups/#{group.name}">@#{group.name.capitalize}</a> <span class="mention">@somemention</span></p>|
+          "hi\n@user. @GROUP @somemention @group2",
+          %Q|<p>hi<br>\n<a class="mention" href="/u/user">@user</a>. <a class="mention-group" href="/groups/group">@GROUP</a> <span class="mention">@somemention</span> <a class="mention-group" href="/groups/group2">@group2</a></p>|
         ]
       ].each do |input, expected|
         expect(PrettyText.cook(input)).to eq(expected)

GitHub

3 Likes

cc @tgxworld - this fixes the case where the name in the database has capital letters. The case where the user input had mixed case was already handled.

2 Likes

Thanks for the fix :+1:

2 Likes