Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(PUP-1211) Force registry value encoding to match code page #2229

Merged

Conversation

joshcooper
Copy link
Contributor

Ruby uses ANSI versions of Win32 APIs to read values from the registry. The
encoding of these strings depends on the active code page. However, ruby
incorrectly sets the string encoding to US-ASCII.[1]

As a result, if you try to perform a regex match on the string, and the string
contains the registered trademark symbol ®, then ruby will raise an error
saying 'Invalid byte sequence in US-ASCII'

This commit forces the encoding of REG_SZ, REG_EXPAND_SZ, and REG_MULTI_SZ to
the encoding for the active code page. So if the active code page is 1252, the
ruby encoding will be Encoding::CP1252.

See https://bugs.ruby-lang.org/issues/8943

@kylog
Copy link

kylog commented Jan 7, 2014

I think this is PUP-1211 actually.

@joshcooper
Copy link
Contributor Author

@kylog good catch, updated commit message

Ruby uses ANSI versions of Win32 APIs to read values from the registry. The
encoding of these strings depends on the active code page. However, ruby
incorrectly sets the string encoding to US-ASCII.[1]

As a result, if you try to perform a regex match on the string, and the string
contains the registered trademark symbol, 0xAE, then ruby will raise an error
saying 'Invalid byte sequence in US-ASCII'

This commit forces the encoding of REG_SZ, REG_EXPAND_SZ, and REG_MULTI_SZ to
the encoding for the active code page. So if the active code page is 1252, the
ruby encoding will be `Encoding::CP1252`.

See https://bugs.ruby-lang.org/issues/8943
@joshcooper
Copy link
Contributor Author

Travis failed on 4582499, because Puppet::Util::Windows::Registry does get loaded on non-Windows platforms, unlike all of the other Puppet::Util::Windows::* modules. So I wrapped the native calls in a method that lazily initializes the registry encoding.

kylog pushed a commit that referenced this pull request Jan 8, 2014
…ry-encoding

(PUP-1211) Force registry value encoding to match code page
@kylog kylog merged commit 1f83be6 into puppetlabs:stable Jan 8, 2014
@joshcooper joshcooper deleted the issue/stable/PUP-1211-registry-encoding branch February 5, 2016 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants