diff --git a/Changelog.md b/Changelog.md index 1d886ee17..e70582664 100644 --- a/Changelog.md +++ b/Changelog.md @@ -47,6 +47,7 @@ Read more in [#4249](https://github.com/diaspora/diaspora/pull/4249) and [#4883] * Do not replace earlier appearances of the name while mentioning somebody [#4868](https://github.com/diaspora/diaspora/issues/4868) * Catch exceptions when trying to decode an invalid URI [#4874](https://github.com/diaspora/diaspora/issues/4874) * Redirect to the stream when switching the mobile publisher to desktop [#4806](https://github.com/diaspora/diaspora/issues/4806) +* Parsing mention witch contain in username special characters [#4919](https://github.com/diaspora/diaspora/pull/4919) ## Features * You can report a single post or comment by clicking the correct icon in the controler section [#4517](https://github.com/diaspora/diaspora/pull/4517) [#4781](https://github.com/diaspora/diaspora/pull/4781) diff --git a/lib/diaspora/mentionable.rb b/lib/diaspora/mentionable.rb index 355b46174..425b5b379 100644 --- a/lib/diaspora/mentionable.rb +++ b/lib/diaspora/mentionable.rb @@ -5,11 +5,21 @@ module Diaspora::Mentionable # ex. # "message @{User Name; user@pod.net} text" # will yield "User Name" and "user@pod.net" - REGEX = /@\{([^;]+); ([^\}]+)\}/ + REGEX = /(@\{([^\}]+)\})/ # class attribute that will be added to all mention html links PERSON_HREF_CLASS = "mention hovercardable" + def self.mention_attrs(mention_str) + mention = mention_str.match(REGEX)[2] + del_pos = mention.rindex(/;/) + + name = mention[0..(del_pos-1)].strip + handle = mention[(del_pos+1)..-1].strip + + [name, handle] + end + # takes a message text and returns the text with mentions in (html escaped) # plain text or formatted with html markup linking to user profiles. # default is html output. @@ -22,7 +32,7 @@ module Diaspora::Mentionable people = [*people] msg_text.to_s.gsub(REGEX) {|match_str| - name, handle = match_str.match(REGEX).captures + name, handle = mention_attrs(match_str) person = people.find {|p| p.diaspora_handle == handle } ERB::Util.h(MentionsInternal.mention_link(person, name, opts)) @@ -35,7 +45,10 @@ module Diaspora::Mentionable # @param [String] text containing mentions # @return [Array] array of people def self.people_from_string(msg_text) - identifiers = msg_text.to_s.scan(REGEX).map(&:last) + identifiers = msg_text.to_s.scan(REGEX).map do |match_str| + _, handle = mention_attrs(match_str.first) + handle + end return [] if identifiers.empty? Person.where(diaspora_handle: identifiers) @@ -58,9 +71,8 @@ module Diaspora::Mentionable .map(&:person) msg_text.to_s.gsub(REGEX) {|match_str| - name, handle = match_str.match(REGEX).captures + name, handle = mention_attrs(match_str) person = mentioned_ppl.find {|p| p.diaspora_handle == handle } - mention = MentionsInternal.profile_link(person, name) unless aspects_ppl.include?(person) mention || match_str diff --git a/spec/lib/diaspora/mentionable_spec.rb b/spec/lib/diaspora/mentionable_spec.rb index 754141405..6e60804a0 100644 --- a/spec/lib/diaspora/mentionable_spec.rb +++ b/spec/lib/diaspora/mentionable_spec.rb @@ -9,14 +9,14 @@ describe Diaspora::Mentionable do @test_txt = <<-STR This post contains a lot of mentions one @{Alice A; #{@people[0].diaspora_handle}}, -two @{Bob B ; #{@people[1].diaspora_handle}}and finally -three @{Eve E; #{@people[2].diaspora_handle}}. +two @{Bob B; #{@people[1].diaspora_handle}} and finally +three @{"Eve> E; #{@people[2].diaspora_handle}}. STR @test_txt_plain = <<-STR This post contains a lot of mentions one Alice A, two Bob B and finally -three Eve E. +three "Eve> E. STR @status_msg = FactoryGirl.build(:status_message, text: @test_txt) end @@ -31,6 +31,15 @@ STR end end + it 'should work correct when message is escaped html' do + raw_msg = @status_msg.raw_message + fmt_msg = Diaspora::Mentionable.format(CGI::escapeHTML(raw_msg), @people) + + @people.each do |person| + fmt_msg.should include person_link(person, class: 'mention hovercardable') + end + end + it 'escapes the link title (name)' do p = @people[0].profile p.first_name = ""