From 0d16c36d0ab2afa2ec79b72b229e69c141ebdaba Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Thu, 23 Feb 2023 13:15:36 -0800 Subject: [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 `
' -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] --- ext/win32/lib/win32/registry.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'ext') diff --git a/ext/win32/lib/win32/registry.rb b/ext/win32/lib/win32/registry.rb index 92b95d1bf7..c801b1327b 100644 --- a/ext/win32/lib/win32/registry.rb +++ b/ext/win32/lib/win32/registry.rb @@ -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 -- cgit v1.2.3