diff --git a/Changelog.md b/Changelog.md index f56a25dbe..89a73fd74 100644 --- a/Changelog.md +++ b/Changelog.md @@ -87,6 +87,7 @@ Ruby 2.0 is no longer officially supported. * Fix the logo in emails [#6013](https://github.com/diaspora/diaspora/pull/6013) * Disable autocorrect for username on mobile sign in [#6028](https://github.com/diaspora/diaspora/pull/6028) * Fix broken default avatars in the database [#6014](https://github.com/diaspora/diaspora/pull/6014) +* Only strip text direction codepoints around hashtags [#6067](https://github.com/diaspora/diaspora/issues/6067) ## Features * Hide post title of limited post in comment notification email [#5843](https://github.com/diaspora/diaspora/pull/5843) diff --git a/lib/diaspora/message_renderer.rb b/lib/diaspora/message_renderer.rb index 9d137f9ef..85d044142 100644 --- a/lib/diaspora/message_renderer.rb +++ b/lib/diaspora/message_renderer.rb @@ -16,7 +16,7 @@ module Diaspora end def normalize message - message.delete("\u202a-\u202e\u200b-\u200f") + message.gsub(/[\u202a\u202b]#[\u200e\u200f\u202d\u202e](\S+)\u202c/u, "#\\1") end end diff --git a/spec/lib/diaspora/message_renderer_spec.rb b/spec/lib/diaspora/message_renderer_spec.rb index 9c152b1e6..5929480d4 100644 --- a/spec/lib/diaspora/message_renderer_spec.rb +++ b/spec/lib/diaspora/message_renderer_spec.rb @@ -1,7 +1,12 @@ require 'spec_helper' describe Diaspora::MessageRenderer do - def message text, opts={} + MESSAGE_NORMALIZTIONS = { + "\u202a#\u200eUSA\u202c" => "#USA", + "ള്" => "ള്" + } + + def message(text, opts={}) Diaspora::MessageRenderer.new(text, opts) end @@ -122,10 +127,10 @@ describe Diaspora::MessageRenderer do ).to include 'href="http://joindiaspora.com/"' end - it 'normalizes' do - expect( - message("\u202a#\u200eUSA\u202c").markdownified - ).to eq %(
\n) + it "normalizes" do + MESSAGE_NORMALIZTIONS.each do |input, output| + expect(message(input).plain_text_for_json).to eq output + end end context 'when formatting status messages' do @@ -218,10 +223,10 @@ describe Diaspora::MessageRenderer do end describe "#plain_text_for_json" do - it 'normalizes' do - expect( - message("\u202a#\u200eUSA\u202c").plain_text_for_json - ).to eq '#USA' + it "normalizes" do + MESSAGE_NORMALIZTIONS.each do |input, output| + expect(message(input).plain_text_for_json).to eq output + end end end end