From 35da56109f9774a52386b175473241f89f7d7568 Mon Sep 17 00:00:00 2001 From: Dennis Schubert Date: Tue, 11 Feb 2020 18:11:38 +0100 Subject: [PATCH] Create a dup string from the return value of .truncate. Due to a bug in Rails, .truncate returns a frozen string if the string actually changed, but not if there are no changes. This leads to inconsistent behaviour, and broken tests. This was fixed upstream, see https://github.com/rails/rails/pull/36109, but the fix did not make it into 5.2.x, so we have to work around for the time being. --- lib/diaspora/message_renderer.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/diaspora/message_renderer.rb b/lib/diaspora/message_renderer.rb index 4477ae587..0072cbd57 100644 --- a/lib/diaspora/message_renderer.rb +++ b/lib/diaspora/message_renderer.rb @@ -35,11 +35,12 @@ module Diaspora def append_and_truncate if options[:truncate] - @message = message.truncate options[:truncate]-options[:append].to_s.size + # TODO: Remove .dup when upgrading to Rails 6.x. + @message = @message.truncate(options[:truncate] - options[:append].to_s.size).dup end - message << options[:append].to_s - message << options[:append_after_truncate].to_s + @message << options[:append].to_s + @message << options[:append_after_truncate].to_s end def escape