mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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("code").remove
|
||||||
cooked_stripped.css(".onebox").remove
|
cooked_stripped.css(".onebox").remove
|
||||||
|
|
||||||
results = cooked_stripped.to_html.scan(PrettyText.mention_matcher)
|
@raw_mentions = cooked_stripped.to_html
|
||||||
@raw_mentions = results.uniq.map { |un| un.first.downcase.sub!(/^@/, '') }
|
.scan(PrettyText.mention_matcher)
|
||||||
|
.flatten
|
||||||
|
.map(&:downcase)
|
||||||
|
.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
# from rack ... compat with ruby 2.2
|
# from rack ... compat with ruby 2.2
|
||||||
|
@ -74,7 +74,7 @@ module PrettyText
|
|||||||
@ctx_init = Mutex.new
|
@ctx_init = Mutex.new
|
||||||
|
|
||||||
def self.mention_matcher
|
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
|
end
|
||||||
|
|
||||||
def self.app_root
|
def self.app_root
|
||||||
|
@ -205,5 +205,10 @@ describe PostAnalyzer do
|
|||||||
post_analyzer = PostAnalyzer.new("@Jake @Finn @Jake_Old", default_topic_id)
|
post_analyzer = PostAnalyzer.new("@Jake @Finn @Jake_Old", default_topic_id)
|
||||||
expect(post_analyzer.raw_mentions).to eq(['jake', 'finn', 'jake_old'])
|
expect(post_analyzer.raw_mentions).to eq(['jake', 'finn', 'jake_old'])
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user