Remove { and } from the name when backporting mentions

Because } is not compatible with the regex.
This commit is contained in:
Benjamin Neff 2017-01-30 23:46:09 +01:00
parent 19e122264b
commit 84e2a131cf
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
2 changed files with 9 additions and 1 deletions

View file

@ -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

View file

@ -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)