FIX: mentions regex server-side (ie. don't count email addresses)
This commit is contained in:
parent
65e808b26d
commit
96aa5b865f
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue