No search result if filtered by unicode username

I use a plugin to add the advanced_filter by following code, and it satisfies my needs.

if SiteSetting.unicode_usernames?
    regexp = Regexp.new("(?i-mx:^\\@([a-zA-Z0-9_\\-.#{SiteSetting.allowed_unicode_username_characters}]+)$)")
    Search.advanced_filter(regexp) do |posts, match|
      username = match.downcase
  
      user_id = User.where(staged: false).where(username_lower: username).pluck_first(:id)
  
      if !user_id && username == "me"
        user_id = @guardian.user&.id
      end
  
      if user_id
        posts.where("posts.user_id = #{user_id}")
      else
        posts.where("1 = 0")
      end
    end
  end

But I don’t know how to modify the core properly, especially when allowed_unicode_username_characters is a variable. Maybe a simple but probably wrong solution is to change advanced_filter(/^\@([a-zA-Z0-9_\-.]+)$/i) to advanced_filter(/^\@(.+)$/i), just like you did in advanced_filter(/^user:(.+)$/i).

2 Likes