Merge pull request #8398 from SuperTux88/fix-mentions-with-underscores
Escape mentions before parsing message with markdown for mobile UI
This commit is contained in:
commit
acc76a383f
4 changed files with 26 additions and 0 deletions
|
|
@ -53,6 +53,7 @@ We use yarn to install the frontend dependencies now, so you need to have that i
|
|||
* Make inline code inside links show the link color [#8387](https://github.com/diaspora/diaspora/pull/8387)
|
||||
* Fix fetching public posts on first account search was missing some data [#8390](https://github.com/diaspora/diaspora/pull/8390)
|
||||
* Add redirect from mobile UI photo URLs to post when not using mobile UI [#8400](https://github.com/diaspora/diaspora/pull/8400)
|
||||
* Escape mentions before markdown parsing in mobile UI [#8398](https://github.com/diaspora/diaspora/pull/8398)
|
||||
|
||||
## Features
|
||||
* Add client-side cropping of profile image uploads [#7581](https://github.com/diaspora/diaspora/pull/7581)
|
||||
|
|
|
|||
|
|
@ -71,6 +71,16 @@ module Diaspora::Mentionable
|
|||
}
|
||||
end
|
||||
|
||||
# Escapes special chars in mentions to not be parsed as markdown
|
||||
#
|
||||
# @param [String] text containing mentions
|
||||
# @return [String] escaped message
|
||||
def self.escape_for_markdown(msg_text)
|
||||
msg_text.to_s.gsub(REGEX) {|match_str|
|
||||
match_str.gsub("_", "\\_")
|
||||
}
|
||||
end
|
||||
|
||||
private_class_method def self.find_or_fetch_person_by_identifier(identifier)
|
||||
Person.find_or_fetch_by_identifier(identifier) if Validation::Rule::DiasporaId.new.valid_value?(identifier)
|
||||
rescue DiasporaFederation::Discovery::DiscoveryError
|
||||
|
|
|
|||
|
|
@ -71,6 +71,10 @@ module Diaspora
|
|||
end
|
||||
end
|
||||
|
||||
def escape_mentions_for_markdown
|
||||
@message = Diaspora::Mentionable.escape_for_markdown(message)
|
||||
end
|
||||
|
||||
def render_mentions
|
||||
unless options[:disable_hovercards] || options[:mentioned_people].empty?
|
||||
@message = Diaspora::Mentionable.format message, options[:mentioned_people]
|
||||
|
|
@ -210,6 +214,7 @@ module Diaspora
|
|||
normalize
|
||||
diaspora_links
|
||||
camo_urls if AppConfig.privacy.camo.proxy_markdown_images?
|
||||
escape_mentions_for_markdown
|
||||
markdownify
|
||||
render_mentions
|
||||
render_tags
|
||||
|
|
|
|||
|
|
@ -183,6 +183,16 @@ describe Diaspora::MessageRenderer do
|
|||
).to match(/hovercard/)
|
||||
end
|
||||
|
||||
it "does not parse mentions as markdown" do
|
||||
new_person = FactoryBot.create(:person, diaspora_handle: "__underscore__@example.org")
|
||||
expect(
|
||||
message(
|
||||
"Hey @{#{new_person.diaspora_handle}}!",
|
||||
mentioned_people: [new_person]
|
||||
).markdownified
|
||||
).to match(%r{>#{new_person.name}</a>})
|
||||
end
|
||||
|
||||
it 'should process text with both a hashtag and a link' do
|
||||
expect(
|
||||
message("Test #tag?\nhttps://joindiaspora.com\n").markdownified
|
||||
|
|
|
|||
Loading…
Reference in a new issue