rails/activesupport/lib
Rosa Gutierrez 71a74ad035
Preserve encoding on truncate_bytes (#51313)
String.new with no arguments returns the empty string with ASCII-8BIT
encoding. Then, depending on each grapheme cluster of the string and
on the omission string, the resulting string might keep the ASCII-8BIT
encoding. With this change, we preserve the encoding of the original
string instead.

Note that String.new accepts an `encoding` keyword argument, like
```
String.new(encoding: Encoding::UTF_8)
```
However, instead of using that, we rely on `force_encoding` to set the
original encoding. This is so that String subclasses don't need to
preserve this keyword argument. For example, SafeBuffer doesn't.
Thanks to @jeremy for catching this!
2024-03-12 15:39:21 -07:00
..
active_support Preserve encoding on truncate_bytes (#51313) 2024-03-12 15:39:21 -07:00
active_support.rb Refactor Module#delegate inside ActiveSupport::Delegation 2024-01-25 11:51:00 +01:00