From 833af461ab5d9e170306172b68541bd62b09201a Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 24 Feb 2016 17:47:55 +1100 Subject: [PATCH] FIX: stop using regex to detect mentions --- app/models/post_analyzer.rb | 16 +++++++++++----- lib/pretty_text.rb | 4 ---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/models/post_analyzer.rb b/app/models/post_analyzer.rb index cf20921cc..ce0629352 100644 --- a/app/models/post_analyzer.rb +++ b/app/models/post_analyzer.rb @@ -52,11 +52,17 @@ class PostAnalyzer cooked_stripped.css("code").remove cooked_stripped.css(".onebox").remove - @raw_mentions = cooked_stripped.to_html - .scan(PrettyText.mention_matcher) - .flatten - .map(&:downcase) - .uniq + raw_mentions = cooked_stripped.css('.mention').map do |e| + if name = e.inner_text + name = name[1..-1] + name.downcase! if name + name + end + end + + raw_mentions.compact! + raw_mentions.uniq! + @raw_mention = raw_mentions end # from rack ... compat with ruby 2.2 diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb index e0afa431d..e41a8ad41 100644 --- a/lib/pretty_text.rb +++ b/lib/pretty_text.rb @@ -72,10 +72,6 @@ module PrettyText @mutex = Mutex.new @ctx_init = Mutex.new - def self.mention_matcher - Regexp.new("\\W@([\\w\\-]{#{SiteSetting.min_username_length},#{SiteSetting.max_username_length}})\\b") - end - def self.app_root Rails.root end