Issue #22416 has been reported by nobu (Nobuyoshi Nakada). ---------------------------------------- Bug #22416: Respect timezone abbreviation encodings in `Time#strftime` https://bugs.ruby-lang.org/issues/22416 * Author: nobu (Nobuyoshi Nakada) * Status: Open * Backport: 3.3: REQUIRED, 3.4: REQUIRED, 4.0: REQUIRED ---------------------------------------- `Time#strftime` treats non-ASCII timezone abbreviations as if their bytes use the locale encoding. However, a timezone object's `abbr` method can return a `String` in another encoding. In that case, formatting `%Z` can produce corrupted text or a result with an unexpected encoding. Timezone objects have been supported since Ruby 2.6.0, so this issue affects Ruby 2.6.0 and later. Reproduction: ```ruby zone = Object.new def zone.local_to_utc(t) = t def zone.utc_to_local(t) = t def zone.abbr(t) = "東京標準時".encode(Encoding::Shift_JIS) time = Time.new(2020, 1, 1, 0, 0, 0, zone) result = time.strftime("☆%Z") p result p result.encoding ``` Expected: `result` contains `☆東京標準時` and is valid UTF-8. Instead, the text may be corrupted because the abbreviation's bytes are interpreted using the locale encoding. -- https://bugs.ruby-lang.org/