diff --git a/app/models/post_analyzer.rb b/app/models/post_analyzer.rb index dce65b4e8d8..cf20921cca3 100644 --- a/app/models/post_analyzer.rb +++ b/app/models/post_analyzer.rb @@ -52,8 +52,11 @@ class PostAnalyzer cooked_stripped.css("code").remove cooked_stripped.css(".onebox").remove - results = cooked_stripped.to_html.scan(PrettyText.mention_matcher) - @raw_mentions = results.uniq.map { |un| un.first.downcase.sub!(/^@/, '') } + @raw_mentions = cooked_stripped.to_html + .scan(PrettyText.mention_matcher) + .flatten + .map(&:downcase) + .uniq end # from rack ... compat with ruby 2.2 diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb index 126f3358c2e..dd2d225a5cf 100644 --- a/lib/pretty_text.rb +++ b/lib/pretty_text.rb @@ -74,7 +74,7 @@ module PrettyText @ctx_init = Mutex.new def self.mention_matcher - Regexp.new("(\@[a-zA-Z0-9_]{#{User.username_length.begin},#{User.username_length.end}})") + Regexp.new("\\W@(\\w{#{SiteSetting.min_username_length},#{SiteSetting.max_username_length}})\\b") end def self.app_root diff --git a/spec/models/post_analyzer_spec.rb b/spec/models/post_analyzer_spec.rb index 096e90014f2..57e68ee88a1 100644 --- a/spec/models/post_analyzer_spec.rb +++ b/spec/models/post_analyzer_spec.rb @@ -205,5 +205,10 @@ describe PostAnalyzer do post_analyzer = PostAnalyzer.new("@Jake @Finn @Jake_Old", default_topic_id) expect(post_analyzer.raw_mentions).to eq(['jake', 'finn', 'jake_old']) end + + it "ignores emails" do + post_analyzer = PostAnalyzer.new("1@test.com 1@best.com @best @not", default_topic_id) + expect(post_analyzer.raw_mentions).to eq(['best', 'not']) + end end end