From 84e2a131cfecff8587e87e401bd52523b21b3e3a Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Mon, 30 Jan 2017 23:46:09 +0100 Subject: [PATCH] Remove { and } from the name when backporting mentions Because } is not compatible with the regex. --- lib/diaspora/mentionable.rb | 2 +- spec/lib/diaspora/mentionable_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/diaspora/mentionable.rb b/lib/diaspora/mentionable.rb index f1b8cc918..de9cfb5f3 100644 --- a/lib/diaspora/mentionable.rb +++ b/lib/diaspora/mentionable.rb @@ -75,7 +75,7 @@ module Diaspora::Mentionable text.to_s.gsub(NEW_SYNTAX_REGEX) do |match_str| _, diaspora_id = mention_attrs(match_str) person = find_or_fetch_person_by_identifier(diaspora_id) - old_syntax = "@{#{person.name}; #{diaspora_id}}" if person + old_syntax = "@{#{person.name.delete('{}')}; #{diaspora_id}}" if person old_syntax || match_str end end diff --git a/spec/lib/diaspora/mentionable_spec.rb b/spec/lib/diaspora/mentionable_spec.rb index b01161a82..f48e495fa 100644 --- a/spec/lib/diaspora/mentionable_spec.rb +++ b/spec/lib/diaspora/mentionable_spec.rb @@ -183,6 +183,14 @@ STR expect(Diaspora::Mentionable.backport_mention_syntax(text)).to eq(expected_text) end + it "removes curly braces from name of the mentioned person when adding it" do + profile = FactoryGirl.build(:profile, first_name: "{Alice}", last_name: "(Smith) [123]") + person = FactoryGirl.create(:person, profile: profile) + text = "mention @{#{person.diaspora_handle}} text" + expected_text = "mention @{Alice (Smith) [123]; #{person.diaspora_handle}} text" + expect(Diaspora::Mentionable.backport_mention_syntax(text)).to eq(expected_text) + end + it "does not change the text, when the mention includes a name" do text = "mention @{#{@names[0]}; #{@people[0].diaspora_handle}} text" expect(Diaspora::Mentionable.backport_mention_syntax(text)).to eq(text)