Merge pull request #4919 from hpetru/4776-mention-on-mobile
Unescape text before add mention, this commit solve #4776 Conflicts: Changelog.md
This commit is contained in:
commit
cbd9c56a7a
3 changed files with 30 additions and 8 deletions
|
|
@ -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)
|
* 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)
|
* 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)
|
* 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
|
## 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)
|
* 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)
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,21 @@ module Diaspora::Mentionable
|
||||||
# ex.
|
# ex.
|
||||||
# "message @{User Name; user@pod.net} text"
|
# "message @{User Name; user@pod.net} text"
|
||||||
# will yield "User Name" and "user@pod.net"
|
# will yield "User Name" and "user@pod.net"
|
||||||
REGEX = /@\{([^;]+); ([^\}]+)\}/
|
REGEX = /(@\{([^\}]+)\})/
|
||||||
|
|
||||||
# class attribute that will be added to all mention html links
|
# class attribute that will be added to all mention html links
|
||||||
PERSON_HREF_CLASS = "mention hovercardable"
|
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)
|
# takes a message text and returns the text with mentions in (html escaped)
|
||||||
# plain text or formatted with html markup linking to user profiles.
|
# plain text or formatted with html markup linking to user profiles.
|
||||||
# default is html output.
|
# default is html output.
|
||||||
|
|
@ -22,7 +32,7 @@ module Diaspora::Mentionable
|
||||||
people = [*people]
|
people = [*people]
|
||||||
|
|
||||||
msg_text.to_s.gsub(REGEX) {|match_str|
|
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 }
|
person = people.find {|p| p.diaspora_handle == handle }
|
||||||
|
|
||||||
ERB::Util.h(MentionsInternal.mention_link(person, name, opts))
|
ERB::Util.h(MentionsInternal.mention_link(person, name, opts))
|
||||||
|
|
@ -35,7 +45,10 @@ module Diaspora::Mentionable
|
||||||
# @param [String] text containing mentions
|
# @param [String] text containing mentions
|
||||||
# @return [Array<Person>] array of people
|
# @return [Array<Person>] array of people
|
||||||
def self.people_from_string(msg_text)
|
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?
|
return [] if identifiers.empty?
|
||||||
Person.where(diaspora_handle: identifiers)
|
Person.where(diaspora_handle: identifiers)
|
||||||
|
|
@ -58,9 +71,8 @@ module Diaspora::Mentionable
|
||||||
.map(&:person)
|
.map(&:person)
|
||||||
|
|
||||||
msg_text.to_s.gsub(REGEX) {|match_str|
|
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 }
|
person = mentioned_ppl.find {|p| p.diaspora_handle == handle }
|
||||||
|
|
||||||
mention = MentionsInternal.profile_link(person, name) unless aspects_ppl.include?(person)
|
mention = MentionsInternal.profile_link(person, name) unless aspects_ppl.include?(person)
|
||||||
|
|
||||||
mention || match_str
|
mention || match_str
|
||||||
|
|
|
||||||
|
|
@ -9,14 +9,14 @@ describe Diaspora::Mentionable do
|
||||||
@test_txt = <<-STR
|
@test_txt = <<-STR
|
||||||
This post contains a lot of mentions
|
This post contains a lot of mentions
|
||||||
one @{Alice A; #{@people[0].diaspora_handle}},
|
one @{Alice A; #{@people[0].diaspora_handle}},
|
||||||
two @{Bob B ; #{@people[1].diaspora_handle}}and finally
|
two @{Bob B; #{@people[1].diaspora_handle}} and finally
|
||||||
three @{Eve E; #{@people[2].diaspora_handle}}.
|
three @{"Eve> E; #{@people[2].diaspora_handle}}.
|
||||||
STR
|
STR
|
||||||
@test_txt_plain = <<-STR
|
@test_txt_plain = <<-STR
|
||||||
This post contains a lot of mentions
|
This post contains a lot of mentions
|
||||||
one Alice A,
|
one Alice A,
|
||||||
two Bob B and finally
|
two Bob B and finally
|
||||||
three Eve E.
|
three "Eve> E.
|
||||||
STR
|
STR
|
||||||
@status_msg = FactoryGirl.build(:status_message, text: @test_txt)
|
@status_msg = FactoryGirl.build(:status_message, text: @test_txt)
|
||||||
end
|
end
|
||||||
|
|
@ -31,6 +31,15 @@ STR
|
||||||
end
|
end
|
||||||
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
|
it 'escapes the link title (name)' do
|
||||||
p = @people[0].profile
|
p = @people[0].profile
|
||||||
p.first_name = "</a><script>alert('h')</script>"
|
p.first_name = "</a><script>alert('h')</script>"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue