Skip to content
  • Rosa Gutierrez's avatar
    71a74ad0
    Preserve encoding on `truncate_bytes` (#51313) · 71a74ad0
    Rosa Gutierrez authored
    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!
    71a74ad0
    Preserve encoding on `truncate_bytes` (#51313)
    Rosa Gutierrez authored
    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!
Loading