Skip to content

Commit

Permalink
Remove implicit conversion of objects into String by `ActiveSupport…
Browse files Browse the repository at this point in the history
…::SafeBuffer`
  • Loading branch information
rafaelfranca committed Mar 3, 2023
1 parent f0ddb77 commit f02998d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 18 deletions.
4 changes: 4 additions & 0 deletions activesupport/CHANGELOG.md
@@ -1,3 +1,7 @@
* Remove implicit conversion of objects into `String` by `ActiveSupport::SafeBuffer`.

*Rafael Mendonça França*

* Remove deprecated `active_support/core_ext/range/include_time_with_zone` file.

*Rafael Mendonça França*
Expand Down
Expand Up @@ -198,22 +198,7 @@ def implicit_html_escape_interpolated_argument(arg)
if !html_safe? || arg.html_safe?
arg
else
arg_string = begin
arg.to_str
rescue NoMethodError => error
if error.name == :to_str
str = arg.to_s
ActiveSupport.deprecator.warn <<~MSG.squish
Implicit conversion of #{arg.class} into String by ActiveSupport::SafeBuffer
is deprecated and will be removed in Rails 7.1.
You must explicitly cast it to a String.
MSG
str
else
raise
end
end
CGI.escapeHTML(arg_string)
CGI.escapeHTML(arg.to_str)
end
end

Expand Down
3 changes: 1 addition & 2 deletions activesupport/test/core_ext/string_ext_test.rb
Expand Up @@ -836,10 +836,9 @@ def to_s

test "Adding an object not responding to `#to_str` to a safe string is deprecated" do
string = @string.html_safe
assert_deprecated("Implicit conversion of #{@to_s_object.class} into String by ActiveSupport::SafeBuffer is deprecated", ActiveSupport.deprecator) do
assert_raises(NoMethodError) do
string << @to_s_object
end
assert_equal "helloto_s", string
end

test "Adding an object to a safe string returns a safe string" do
Expand Down
2 changes: 2 additions & 0 deletions guides/source/7_1_release_notes.md
Expand Up @@ -151,6 +151,8 @@ Please refer to the [Changelog][active-support] for detailed changes.

* Remove deprecated `active_support/core_ext/range/include_time_with_zone` file.

* Remove implicit conversion of objects into `String` by `ActiveSupport::SafeBuffer`.

### Deprecations

* Deprecate `config.active_support.disable_to_s_conversion`.
Expand Down

0 comments on commit f02998d

Please sign in to comment.