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.
This commit is contained in:
Dennis Schubert 2020-02-11 18:11:38 +01:00 committed by Benjamin Neff
parent 75ef13b5d1
commit 35da56109f
No known key found for this signature in database
GPG key ID: 971464C3F1A90194

View file

@ -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