FIX: Muted/Ignore should prevent PMs regardless of case sensitivity

FIX: Muted/Ignore should prevent PMs regardless of case sensitivity

diff --git a/lib/post_creator.rb b/lib/post_creator.rb
index c3b9556..6a9e4ca 100644
--- a/lib/post_creator.rb
+++ b/lib/post_creator.rb
@@ -96,7 +96,7 @@ class PostCreator
     end
 
     if @opts[:target_usernames].present? && !skip_validations? && !@user.staff?
-      names = @opts[:target_usernames].split(',')
+      names = @opts[:target_usernames].split(',').flatten.map(&:downcase)
 
       # Make sure max_allowed_message_recipients setting is respected
       max_allowed_message_recipients = SiteSetting.max_allowed_message_recipients
@@ -111,7 +111,7 @@ class PostCreator
       end
 
       # Make sure none of the users have muted the creator
-      users = User.where(username: names).pluck(:id, :username).to_h
+      users = User.where(username_lower: names).pluck(:id, :username).to_h
 
       User
         .joins("LEFT JOIN user_options ON user_options.user_id = users.id")
diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rb
index 5936959..27fba7c 100644
--- a/spec/components/post_creator_spec.rb
+++ b/spec/components/post_creator_spec.rb
@@ -1203,7 +1203,7 @@ describe PostCreator do
   end
 
   context 'private message to a user that has disabled private messages' do
-    fab!(:another_user) { Fabricate(:user) }
+    fab!(:another_user) { Fabricate(:user, username: 'HelloWorld') }
 
     before do
       another_user.user_option.update!(allow_private_messages: false)
@@ -1224,6 +1224,18 @@ describe PostCreator do
         "not_accepting_pms", username: another_user.username
       ))
     end
+
+    it 'should not be valid if the name is downcased' do
+      post_creator = PostCreator.new(
+        user,
+        title: 'this message is to someone who muted me!',
+        raw: "you will have to see this even if you muted me!",
+        archetype: Archetype.private_message,
+        target_usernames: "#{another_user.username.downcase}"
+      )
+
+      expect(post_creator).to_not be_valid
+    end
   end
 
   context "private message to a muted user" do

GitHub sha: e8756e1a

1 Like