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

Encode CSIDL strings as ascii_compatible #3

Merged
merged 1 commit into from Jul 12, 2013

Conversation

joshcooper
Copy link
Contributor

Ruby does not allow File.join to be called with non-ascii_compatible
encoded strings, like UTF-16LE[1]. As a result, if any of the CSIDL
constants, e.g. COMMON_APPDATA, are used in File.join it fails with:

irb(main):001:0> require 'win32/dir'
irb(main):002:0> File.join(Dir::COMMON_APPDATA, 'foo')
ArgumentError: string contains null byte

The ffi branch calls the wide versions of SHGetFolderPathW, and appears
to always have this issue. The master branch calls the ANSI versions, which
only exhibit the problem when using a non-ASCII locale, e.g. Italian
(locale 0410).

This commit ensures all CSIDL constants are encoded using the default
external encoding, similar to what is done for Dir::getwd.

Note I suspect the junction code has the same problem, e.g. read_junction.

[1] https://bugs.ruby-lang.org/issues/7168

Ruby does not allow `File.join` to be called with non-ascii_compatible
encoded strings, like `UTF-16LE`[1]. As a result, if any of the CSIDL
constants, e.g. COMMON_APPDATA, are used in `File.join` it fails with:

    irb(main):001:0> require 'win32/dir'
    irb(main):002:0> File.join(Dir::COMMON_APPDATA, 'foo')
    ArgumentError: string contains null byte

The ffi branch calls the wide versions of `SHGetFolderPathW`, and appears
to always have this issue. The master branch calls the ANSI versions, which
only exhibit the problem when using a non-ASCII locale, e.g. Italian
(locale 0410).

This commit ensures all CSIDL constants are encoded using the default
external encoding, similar to what is done for `Dir::getwd`.

Note I suspect the junction code has the same problem, e.g. `read_junction`.

[1] https://bugs.ruby-lang.org/issues/7168
@dedalcom
Copy link

indeed, the Dir::COMMON_APPDATA fails (Windows 7, Bulgarian Locale, Ruby 1.9.3-p194)

djberg96 added a commit that referenced this pull request Jul 12, 2013
Encode CSIDL strings as ascii_compatible
@djberg96 djberg96 merged commit 7664900 into chef:ffi Jul 12, 2013
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.

None yet

3 participants