From 51ad59e0d880de4633d18af583be015af229b97d Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 21 Apr 2015 11:45:03 +0200 Subject: [PATCH] Fix bug causing `@whatever` inside code blocks to sometimes be picked up as a user mention. --- CHANGELOG | 3 ++- app/models/concerns/mentionable.rb | 2 +- lib/gitlab/reference_extractor.rb | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b4affd5217a..8d2099e8cf6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,7 +3,8 @@ Please view this file on the master branch, on stable branches it's out of date. v 7.11.0 (unreleased) - Fix clone URL field and X11 Primary selection (Dmitry Medvinsky) - Ignore invalid lines in .gitmodules - - + - Fix bug causing `@whatever` inside an issue's first code block to be picked up as a user mention. + - Fix bug causing `@whatever` inside an inline code snippet (backtick-style) to be picked up as a user mention. - - - diff --git a/app/models/concerns/mentionable.rb b/app/models/concerns/mentionable.rb index acd9a1edc48..aad5e514793 100644 --- a/app/models/concerns/mentionable.rb +++ b/app/models/concerns/mentionable.rb @@ -28,7 +28,7 @@ module Mentionable # Construct a String that contains possible GFM references. def mentionable_text - self.class.mentionable_attrs.map { |attr| send(attr) || '' }.join + self.class.mentionable_attrs.map { |attr| send(attr) }.compact.join("\n\n") end # The GFM reference to this Mentionable, which shouldn't be included in its #references. diff --git a/lib/gitlab/reference_extractor.rb b/lib/gitlab/reference_extractor.rb index a502a8fe9cd..634f70347b5 100644 --- a/lib/gitlab/reference_extractor.rb +++ b/lib/gitlab/reference_extractor.rb @@ -18,8 +18,8 @@ module Gitlab text = text.dup # Remove preformatted/code blocks so that references are not included - text.gsub!(%r{
.*?
|.*?}m) { |match| '' } - text.gsub!(%r{^```.*?^```}m) { |match| '' } + text.gsub!(/^```.*?^```/m, '') + text.gsub!(/[^`]`[^`]*?`[^`]/, '') @references = Hash.new { |hash, type| hash[type] = [] } parse_references(text)