summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2017-03-29 09:37:16 +0000
committerSean McGivern <sean@mcgivern.me.uk>2017-03-29 09:37:16 +0000
commit65cc277d64cb8d6e6faa74cf237fd28a9f9c525d (patch)
tree8488336c5168d65b695973e42cc088d9a812affe
parent839183f2cbbed45bd2a8f8123bd01e2d2b509037 (diff)
parente06015379739ce6ee57318d35d18e274f4e930a6 (diff)
downloadgitlab-ce-65cc277d64cb8d6e6faa74cf237fd28a9f9c525d.tar.gz
Merge branch 'make_user_mentions_case_insensitive' into 'master'
Make user mentions case-insensitive Closes #24493 See merge request !10285
-rw-r--r--changelogs/unreleased/make_user_mentions_case_insensitive.yml4
-rw-r--r--lib/banzai/filter/user_reference_filter.rb4
-rw-r--r--spec/lib/banzai/filter/user_reference_filter_spec.rb8
3 files changed, 14 insertions, 2 deletions
diff --git a/changelogs/unreleased/make_user_mentions_case_insensitive.yml b/changelogs/unreleased/make_user_mentions_case_insensitive.yml
new file mode 100644
index 00000000000..ab114494802
--- /dev/null
+++ b/changelogs/unreleased/make_user_mentions_case_insensitive.yml
@@ -0,0 +1,4 @@
+---
+title: Make user mentions case-insensitive
+merge_request: 10285
+author: blackst0ne
diff --git a/lib/banzai/filter/user_reference_filter.rb b/lib/banzai/filter/user_reference_filter.rb
index fe1f0923136..a798927823f 100644
--- a/lib/banzai/filter/user_reference_filter.rb
+++ b/lib/banzai/filter/user_reference_filter.rb
@@ -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.
diff --git a/spec/lib/banzai/filter/user_reference_filter_spec.rb b/spec/lib/banzai/filter/user_reference_filter_spec.rb
index 9873774909e..63b23dac7ed 100644
--- a/spec/lib/banzai/filter/user_reference_filter_spec.rb
+++ b/spec/lib/banzai/filter/user_reference_filter_spec.rb
@@ -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