Don't match email addresses or foo@bar as user references

This commit is contained in:
Douwe Maan 2017-05-31 17:11:15 -05:00
parent 322c9be816
commit 371ae05c15
3 changed files with 10 additions and 0 deletions

View file

@ -369,6 +369,7 @@ class User < ActiveRecord::Base
# Pattern used to extract `@user` user references from text # Pattern used to extract `@user` user references from text
def reference_pattern def reference_pattern
%r{ %r{
(?<!\w)
#{Regexp.escape(reference_prefix)} #{Regexp.escape(reference_prefix)}
(?<user>#{Gitlab::PathRegex::FULL_NAMESPACE_FORMAT_REGEX}) (?<user>#{Gitlab::PathRegex::FULL_NAMESPACE_FORMAT_REGEX})
}x }x

View file

@ -0,0 +1,4 @@
---
title: Don't match email addresses or foo@bar as user references
merge_request:
author:

View file

@ -16,6 +16,11 @@ describe Banzai::Filter::UserReferenceFilter, lib: true do
expect(reference_filter(act).to_html).to eq(exp) expect(reference_filter(act).to_html).to eq(exp)
end end
it 'ignores references with text before the @ sign' do
exp = act = "Hey foo#{reference}"
expect(reference_filter(act).to_html).to eq(exp)
end
%w(pre code a style).each do |elem| %w(pre code a style).each do |elem|
it "ignores valid references contained inside '#{elem}' element" do it "ignores valid references contained inside '#{elem}' element" do
exp = act = "<#{elem}>Hey #{reference}</#{elem}>" exp = act = "<#{elem}>Hey #{reference}</#{elem}>"