From: "nobu (Nobuyoshi Nakada) via ruby-core" Date: 2026-10-08T04:31:11+00:00 Subject: [ruby-core:127007] [Ruby Bug#22416] Respect timezone abbreviation encodings in `Time#strftime` 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/ ______________________________________________ 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/