From: "k0kubun (Takashi Kokubun) via ruby-core" Date: 2026-10-09T23:07:31+00:00 Subject: [ruby-core:127056] [Ruby Bug#22416] Respect timezone abbreviation encodings in `Time#strftime` Issue #22416 has been updated by k0kubun (Takashi Kokubun). Backport changed from 3.3: REQUIRED, 3.4: REQUIRED, 4.0: REQUIRED to 3.3: REQUIRED, 3.4: REQUIRED, 4.0: DONE ruby_4_0 commit:15212f6c1cf04e18c43ca44601f525a3bbf32b62. ---------------------------------------- Bug #22416: Respect timezone abbreviation encodings in `Time#strftime` https://bugs.ruby-lang.org/issues/22416#change-119453 * Author: nobu (Nobuyoshi Nakada) * Status: Closed * Backport: 3.3: REQUIRED, 3.4: REQUIRED, 4.0: DONE ---------------------------------------- `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/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/