Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Neff <benjamin@coding4coffee.ch>2022-11-01 23:14:41 +0300
committerBenjamin Neff <benjamin@coding4coffee.ch>2022-11-01 23:15:47 +0300
commitacc76a383fb9a7f87e62ba0ad43c6a98247bbca5 (patch)
tree19f5202e499de60810886e0fecd3629249b7446a
parent6af305b2be06c06d6a851cb85fa563c1225b83eb (diff)
parent536c96f2173963154589f54f73e0def362ac864a (diff)
Merge pull request #8398 from SuperTux88/fix-mentions-with-underscores
Escape mentions before parsing message with markdown for mobile UI
-rw-r--r--Changelog.md1
-rw-r--r--lib/diaspora/mentionable.rb10
-rw-r--r--lib/diaspora/message_renderer.rb5
-rw-r--r--spec/lib/diaspora/message_renderer_spec.rb10
4 files changed, 26 insertions, 0 deletions
diff --git a/Changelog.md b/Changelog.md
index 350946272..d288d64b0 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -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)
diff --git a/lib/diaspora/mentionable.rb b/lib/diaspora/mentionable.rb
index 39dc7b085..41dcb79f7 100644
--- a/lib/diaspora/mentionable.rb
+++ b/lib/diaspora/mentionable.rb
@@ -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
diff --git a/lib/diaspora/message_renderer.rb b/lib/diaspora/message_renderer.rb
index 7cb0df3fd..6981e7a20 100644
--- a/lib/diaspora/message_renderer.rb
+++ b/lib/diaspora/message_renderer.rb
@@ -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
diff --git a/spec/lib/diaspora/message_renderer_spec.rb b/spec/lib/diaspora/message_renderer_spec.rb
index a9a12e85b..ca000890e 100644
--- a/spec/lib/diaspora/message_renderer_spec.rb
+++ b/spec/lib/diaspora/message_renderer_spec.rb
@@ -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