diff options
author | tpowell-progress <104777878+tpowell-progress@users.noreply.github.com> | 2023-01-25 06:13:19 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-25 09:13:19 -0500 |
commit | af1405ed41ca25bcc2967bcf97a0448d5cba208d (patch) | |
tree | 56fae7a8cfd266a5bfdf86fdc39717667cc3df8d /lib/ohai/plugins/timezone.rb | |
parent | 18f7869fe79918aadcb11cd890840d9dddd5e49a (diff) | |
download | ohai-af1405ed41ca25bcc2967bcf97a0448d5cba208d.tar.gz |
Force encoding with timezones that include umlauts if zone encoding is IBM437 (#1781)
* If time.zone is encoded in Encoding::IBM437, force to WINDOWS_1252
* Added description of what's going on with the force/encode chain
* Handle umlauts in popen output from Mixlib shellout
Signed-off-by: Thomas Powell <powell@progress.com>
Diffstat (limited to 'lib/ohai/plugins/timezone.rb')
-rw-r--r-- | lib/ohai/plugins/timezone.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/ohai/plugins/timezone.rb b/lib/ohai/plugins/timezone.rb index 1d542e43..d2ab47dc 100644 --- a/lib/ohai/plugins/timezone.rb +++ b/lib/ohai/plugins/timezone.rb @@ -21,5 +21,25 @@ Ohai.plugin(:Timezone) do collect_data(:default) do time Mash.new unless time time[:timezone] = Time.now.getlocal.zone + + # Windows in German display language outputs LATIN1 bytes for .zone, but marks them as + # IBM437, which somehow fails any attempt at conversion to other encodings when + # ä is present, as in the timezone name "Mitteleuropäische Zeit" (Central Europe Time) + # + # Windows-1252 is the legacy encoding for Windows for German that actually + # translates (ISO-8859-1 works as well), but going with the more correct + # encoding name for Windows' implementation of Latin-1 + # + # References + # * [Code Page 437/IBM437](https://en.wikipedia.org/wiki/Code_page_437) + # * [ISO/IEC 8859-1](https://en.wikipedia.org/wiki/ISO/IEC_8859-1) + # * [Windows-1252](https://en.wikipedia.org/wiki/Windows-1252) + if time[:timezone].encoding == Encoding::IBM437 + # Assume encoding is WINDOWS_1252 + time[:timezone] = time[:timezone].force_encoding(Encoding::WINDOWS_1252) + # Re-encode in UTF_8. Note: If other encodings have problems converting + # it might be worth re-encode everything in UTF_8. + time[:timezone] = time[:timezone].encode(Encoding::UTF_8) + end end end |