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 13:20:18 +11:00
committed by GitHub
parent 837bd5a6e5
commit 2944d2cdd6
+1 -1
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)