mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 18:52:45 +08:00
FIX - downcase strings consistently (#10861)
ruby and postgres can treat certain characters differently when downcasing them. So do all the downcasing in ruby so that we get consistent results.
This commit is contained in:
parent
bdbee36961
commit
a1918801a4
|
@ -218,7 +218,7 @@ class TopicCreator
|
||||||
names = usernames.split(',').flatten.map(&:downcase)
|
names = usernames.split(',').flatten.map(&:downcase)
|
||||||
len = 0
|
len = 0
|
||||||
|
|
||||||
User.includes(:user_option).where('lower(username) in (?)', names).find_each do |user|
|
User.includes(:user_option).where('username_lower in (?)', names).find_each do |user|
|
||||||
check_can_send_permission!(topic, user)
|
check_can_send_permission!(topic, user)
|
||||||
@added_users << user
|
@added_users << user
|
||||||
topic.topic_allowed_users.build(user_id: user.id)
|
topic.topic_allowed_users.build(user_id: user.id)
|
||||||
|
|
|
@ -1083,11 +1083,17 @@ describe PostsController do
|
||||||
user_2 = Fabricate(:user)
|
user_2 = Fabricate(:user)
|
||||||
user_3 = Fabricate(:user, username: "foo_bar")
|
user_3 = Fabricate(:user, username: "foo_bar")
|
||||||
|
|
||||||
|
# In certain edge cases, it's possible to end up with a username
|
||||||
|
# containing characters that would normally fail to validate
|
||||||
|
user_4 = Fabricate(:user, username: "Iyi_Iyi")
|
||||||
|
user_4.update_attribute(:username, "İyi_İyi")
|
||||||
|
user_4.update_attribute(:username_lower, "İyi_İyi".downcase)
|
||||||
|
|
||||||
post "/posts.json", params: {
|
post "/posts.json", params: {
|
||||||
raw: 'this is the test content',
|
raw: 'this is the test content',
|
||||||
archetype: 'private_message',
|
archetype: 'private_message',
|
||||||
title: "this is some post",
|
title: "this is some post",
|
||||||
target_recipients: "#{user_2.username},Foo_Bar"
|
target_recipients: "#{user_2.username},Foo_Bar,İyi_İyi"
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(response.status).to eq(200)
|
expect(response.status).to eq(200)
|
||||||
|
@ -1097,7 +1103,7 @@ describe PostsController do
|
||||||
|
|
||||||
expect(new_post.user).to eq(user)
|
expect(new_post.user).to eq(user)
|
||||||
expect(new_topic.private_message?).to eq(true)
|
expect(new_topic.private_message?).to eq(true)
|
||||||
expect(new_topic.allowed_users).to contain_exactly(user, user_2, user_3)
|
expect(new_topic.allowed_users).to contain_exactly(user, user_2, user_3, user_4)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when target_recipients not provided" do
|
context "when target_recipients not provided" do
|
||||||
|
|
Loading…
Reference in New Issue
Block a user