FIX: Ruby 3 does not freeze interpolated string (#14567)

Ruby 2.7 or earlier `+contents` returns self.dup
when `frozen_string_literal: true`. However, Ruby 3.0 returns self
because this string is interpolated one, which is not frozen anymore.

This commit uses self.dup to return duplicated string regardless Ruby
versions.
https://bugs.ruby-lang.org/issues/17104
This commit is contained in:
Yasuo Honda 2021-10-11 11:20:18 +09:00 committed by GitHub
parent 837bd5a6e5
commit 2944d2cdd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,7 +34,7 @@ class TopicEmbed < ActiveRecord::Base
contents = first_paragraph_from(contents)
end
contents ||= ''
contents = +contents << imported_from_html(url)
contents = contents.dup << imported_from_html(url)
url = normalize_url(url)