mirror of
https://github.com/diaspora/diaspora.git
synced 2026-01-09 15:18:11 -05:00
Escape mentions before parsing message with markdown
Usernames that contained underscores were parsed by markdown first. This broke the diaspora IDs and also added weird html at places where it wasn't needed. Escaping them before sending the message through the markdown parser fixes this issue. As underscores are the only allowed character that can be used for markdown that is also allowed inside a diaspora ID, this escaping can be kept pretty simple. This only fixes it for the mobile UI at the moment, for the desktop UI it's probably better to fix it in markdown-it. Related to #7975
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user