summaryrefslogtreecommitdiff
path: root/ext/win32
diff options
context:
space:
mode:
authorJosh Cooper <[email protected]>2023-02-23 13:15:36 -0800
committerHiroshi SHIBATA <[email protected]>2024-09-25 10:43:31 +0900
commit0d16c36d0ab2afa2ec79b72b229e69c141ebdaba (patch)
treec70727e351662e0ff596e85455061a47a4a2d566 /ext/win32
parentc94ea1cccb24a41a5cd5c7e90aec04cb477b367e (diff)
[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]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/7366
Diffstat (limited to 'ext/win32')
-rw-r--r--ext/win32/lib/win32/registry.rb6
1 files changed, 5 insertions, 1 deletions
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