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:
parent
75ef13b5d1
commit
35da56109f
1 changed files with 4 additions and 3 deletions
|
|
@ -35,11 +35,12 @@ module Diaspora
|
||||||
|
|
||||||
def append_and_truncate
|
def append_and_truncate
|
||||||
if options[: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
|
end
|
||||||
|
|
||||||
message << options[:append].to_s
|
@message << options[:append].to_s
|
||||||
message << options[:append_after_truncate].to_s
|
@message << options[:append_after_truncate].to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def escape
|
def escape
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue