diff options
author | Claire McQuin <mcquin@users.noreply.github.com> | 2015-09-01 13:35:22 -0700 |
---|---|---|
committer | Claire McQuin <mcquin@users.noreply.github.com> | 2015-09-01 13:35:22 -0700 |
commit | 3770ec1025fd09d3a3bb393ad955ee2985252a67 (patch) | |
tree | 32581d71136e9ed02acefa84d72fdd050d40b430 | |
parent | 632e4cb3083f3932df3b7fec89a1d52b5d5ed570 (diff) | |
parent | 5d4d979768029a6e396608ab683014946aa1148d (diff) | |
download | chef-3770ec1025fd09d3a3bb393ad955ee2985252a67.tar.gz |
Merge pull request #3850 from chef/mcquin/monkeypatch-win32-registry-write
Monkeypatch Win32::Registry#write
-rw-r--r-- | lib/chef/win32/unicode.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/chef/win32/unicode.rb b/lib/chef/win32/unicode.rb index e7399d5255..ea10dc71d0 100644 --- a/lib/chef/win32/unicode.rb +++ b/lib/chef/win32/unicode.rb @@ -53,3 +53,30 @@ class String Chef::ReservedNames::Win32::Unicode.utf8_to_wide(self) end end + +# https://bugs.ruby-lang.org/issues/11439 +if RUBY_VERSION =~ /^2\.1/ + module Win32 + class Registry + def write(name, type, data) + case type + when REG_SZ, REG_EXPAND_SZ + data = data.to_s.encode(WCHAR) + WCHAR_NUL + when REG_MULTI_SZ + data = data.to_a.map {|s| s.encode(WCHAR)}.join(WCHAR_NUL) << WCHAR_NUL << WCHAR_NUL + when REG_BINARY + data = data.to_s + when REG_DWORD + data = API.packdw(data.to_i) + when REG_DWORD_BIG_ENDIAN + data = [data.to_i].pack('N') + when REG_QWORD + data = API.packqw(data.to_i) + else + raise TypeError, "Unsupported type #{type}" + end + API.SetValue(@hkey, name, type, data, data.bytesize) + end + end + end +end
\ No newline at end of file |