Make user mentions case-insensitive
This commit is contained in:
parent
ad831ace7e
commit
e060153797
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
title: Make user mentions case-insensitive
|
||||
merge_request: 10285
|
||||
author: blackst0ne
|
|
@ -60,7 +60,7 @@ module Banzai
|
|||
self.class.references_in(text) do |match, username|
|
||||
if username == 'all' && !skip_project_check?
|
||||
link_to_all(link_content: link_content)
|
||||
elsif namespace = namespaces[username]
|
||||
elsif namespace = namespaces[username.downcase]
|
||||
link_to_namespace(namespace, link_content: link_content) || match
|
||||
else
|
||||
match
|
||||
|
@ -74,7 +74,7 @@ module Banzai
|
|||
# The keys of this Hash are the namespace paths, the values the
|
||||
# corresponding Namespace objects.
|
||||
def namespaces
|
||||
@namespaces ||= Namespace.where_full_path_in(usernames).index_by(&:full_path)
|
||||
@namespaces ||= Namespace.where_full_path_in(usernames).index_by(&:full_path).transform_keys(&:downcase)
|
||||
end
|
||||
|
||||
# Returns all usernames referenced in the current document.
|
||||
|
|
|
@ -83,6 +83,14 @@ describe Banzai::Filter::UserReferenceFilter, lib: true do
|
|||
expect(doc.css('a').length).to eq 1
|
||||
end
|
||||
|
||||
it 'links to a User with different case-sensitivity' do
|
||||
user = create(:user, username: 'RescueRanger')
|
||||
|
||||
doc = reference_filter("Hey #{user.to_reference.upcase}")
|
||||
expect(doc.css('a').length).to eq 1
|
||||
expect(doc.css('a').text).to eq(user.to_reference)
|
||||
end
|
||||
|
||||
it 'includes a data-user attribute' do
|
||||
doc = reference_filter("Hey #{reference}")
|
||||
link = doc.css('a').first
|
||||
|
|
Loading…
Reference in New Issue