FIX: Support unicode in search filter @username (#18804)

This commit is contained in:
Du Jiajun 2022-11-16 17:42:37 +08:00 committed by GitHub
parent 5b16546358
commit 41e6b516e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -646,10 +646,10 @@ class Search
end
end
advanced_filter(/^\@([a-zA-Z0-9_\-.]+)$/i) do |posts, match|
username = match.downcase
advanced_filter(/^\@(\S+)$/i) do |posts, match|
username = User.normalize_username(match)
user_id = User.where(staged: false).where(username_lower: username).pluck_first(:id)
user_id = User.not_staged.where(username_lower: username).pluck_first(:id)
if !user_id && username == "me"
user_id = @guardian.user&.id

View File

@ -1597,6 +1597,12 @@ RSpec.describe Search do
expect(Search.execute("user:#{post_1.user_id}").posts).to contain_exactly(post_1)
expect(Search.execute("@#{post_1.user.username}").posts).to contain_exactly(post_1)
SiteSetting.unicode_usernames = true
unicode_user = Fabricate(:unicode_user)
post_3 = Fabricate(:post, user: unicode_user, raw: 'post by a unicode user', topic: topic)
expect(Search.execute("@#{post_3.user.username}").posts).to contain_exactly(post_3)
end
context "when searching for posts made by users of a group" do