[win32/registry] Fallback to UTF-8 for unknown codepages

There are some codepages like cp708 for which no ruby encoding exists:

    $ ruby -e "Encoding.find('cp708')"
    Traceback (most recent call last):
    	1: from -e:1:in `<main>'
    -e:1:in `find': unknown encoding name - cp708 (ArgumentError)

win32/registry uses ENCODING to transcode error messages and expand environment
variables from UTF-16LE, so using UTF-8 seems like the best choice and is better
than a hard failure.

This should resolve [Bug #13831]
This commit is contained in:
Josh Cooper 2023-02-23 13:15:36 -08:00 committed by Hiroshi SHIBATA
parent c94ea1cccb
commit 0d16c36d0a
Notes: git 2024-09-25 01:43:49 +00:00

View file

@ -69,7 +69,11 @@ For detail, see the MSDN[http://msdn.microsoft.com/library/en-us/sysinfo/base/pr
WCHAR_NUL = "\0".encode(WCHAR).freeze
WCHAR_CR = "\r".encode(WCHAR).freeze
WCHAR_SIZE = WCHAR_NUL.bytesize
LOCALE = Encoding.find(Encoding.locale_charmap)
begin
LOCALE = Encoding.find(Encoding.locale_charmap)
rescue ArgumentError
LOCALE = Encoding::UTF_8
end
class Registry