Skip to content

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

FIX: allows to query a username made of integers (#25815)

Joffrey JAFFEUX84cd621bdc36
diff --git a/plugins/chat/app/queries/chat/users_from_usernames_and_groups_query.rb b/plugins/chat/app/queries/chat/users_from_usernames_and_groups_query.rb
index 3160f9a2b3a..20a14dd767b 100644
--- a/plugins/chat/app/queries/chat/users_from_usernames_and_groups_query.rb
+++ b/plugins/chat/app/queries/chat/users_from_usernames_and_groups_query.rb
@@ -9,8 +9,8 @@ module Chat
.where(user_options: { chat_enabled: true })
.where(
"username IN (?) OR (groups.name IN (?) AND group_users.user_id IS NOT NULL)",
- usernames,
- groups,
+ usernames&.map(&:to_s),
+ groups&.map(&:to_s),
)
.where.not(id: excluded_user_ids)
.distinct
diff --git a/plugins/chat/spec/queries/chat/users_from_usernames_and_groups_query_spec.rb b/plugins/chat/spec/queries/chat/users_from_usernames_and_groups_query_spec.rb
index 1f881f35966..60d3a2c7402 100644
--- a/plugins/chat/spec/queries/chat/users_from_usernames_and_groups_query_spec.rb
+++ b/plugins/chat/spec/queries/chat/users_from_usernames_and_groups_query_spec.rb
@@ -15,6 +15,12 @@ describe Chat::UsersFromUsernamesAndGroupsQuery do
result = described_class.call(usernames: [user1.username, user4.username], groups: [])
expect(result).to contain_exactly(user1, user4)
end
+
+ it "works with a number" do
+ user = Fabricate(:user, username: 12_345_678)
+ result = described_class.call(usernames: [12_345_678], groups: [])
+ expect(result).to contain_exactly(user)
+ end
end
context "when searching by groups" do
@@ -22,6 +28,12 @@ describe Chat::UsersFromUsernamesAndGroupsQuery do
result = described_class.call(usernames: [], groups: [group1.name])
expect(result).to contain_exactly(user1, user2)
end
+
+ it "works with a number" do
+ group = Fabricate(:public_group, users: [user1, user2], name: 12_345_678)
+ result = described_class.call(usernames: [], groups: [12_345_678])
+ expect(result).to contain_exactly(user1, user2)
+ end
end
context "when searching by both usernames and groups" do