summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Wrock <matt@mattwrock.com>2016-05-06 14:19:03 -0700
committerMatt Wrock <matt@mattwrock.com>2016-05-06 14:19:03 -0700
commit9b71a935fe373aa276393ddacc22d8fec0323132 (patch)
tree2f944d2acdd8961b0e8a64ffd4ab2c4d0d637ada
parent0f5e73eebbb509750a380ccddfaf112ba415dd4a (diff)
downloadchef-9b71a935fe373aa276393ddacc22d8fec0323132.tar.gz
fixes #4897 encode registry enumerated values and keys to utf8 instead of the local codepage
-rw-r--r--lib/chef/monkey_patches/win32/registry.rb11
-rw-r--r--spec/functional/win32/registry_spec.rb1
2 files changed, 12 insertions, 0 deletions
diff --git a/lib/chef/monkey_patches/win32/registry.rb b/lib/chef/monkey_patches/win32/registry.rb
index 1c1a103432..a08d67becf 100644
--- a/lib/chef/monkey_patches/win32/registry.rb
+++ b/lib/chef/monkey_patches/win32/registry.rb
@@ -22,6 +22,17 @@ require "win32/registry"
module Win32
class Registry
+ # ::Win32::Registry#export_string is used when enumerating child
+ # keys and values and re encodes a UTF-16LE to the local codepage.
+ # This can result in encoding incompatibilities if the native codepage
+ # does not support the characters in the registry. There is an open bug
+ # in ruby at https://bugs.ruby-lang.org/issues/11410. Rather than converting
+ # the UTF-16LE originally returned by the win32 api, we encode to UTF-8
+ # which will likely not result in any conversion error.
+ def export_string(str, enc = Encoding.default_internal || "utf-8")
+ str.encode(enc)
+ end
+
module API
extend Chef::ReservedNames::Win32::API::Registry
diff --git a/spec/functional/win32/registry_spec.rb b/spec/functional/win32/registry_spec.rb
index 4a6157a6d5..bcfa0ffd48 100644
--- a/spec/functional/win32/registry_spec.rb
+++ b/spec/functional/win32/registry_spec.rb
@@ -26,6 +26,7 @@ describe "Chef::Win32::Registry", :windows_only do
#Create a registry item
::Win32::Registry::HKEY_CURRENT_USER.create "Software\\Root"
::Win32::Registry::HKEY_CURRENT_USER.create "Software\\Root\\Branch"
+ ::Win32::Registry::HKEY_CURRENT_USER.create "Software\\Root\\BĀ®anch"
::Win32::Registry::HKEY_CURRENT_USER.create "Software\\Root\\Branch\\Flower"
::Win32::Registry::HKEY_CURRENT_USER.open('Software\\Root', Win32::Registry::KEY_ALL_ACCESS) do |reg|
reg["RootType1", Win32::Registry::REG_SZ] = "fibrous"