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

Encoding::CompatibilityError when file path has non-ASCII character under some environment #14

Open
scivola opened this issue Nov 23, 2018 · 0 comments

Comments

@scivola
Copy link

scivola commented Nov 23, 2018

This exception may occur under, for example, Japanese Windows environment.

In the case, the encoding of the string got via ARGV may be not UTF-8 but Windows 31J (a.k.a. Codepage 932).

# demo1.rb

p ARGV.first.encoding
> ruby demo1.rb foo
#<Encoding:Windows-31J>

Generally, two strings which do not contain any non-ASCII character can be joined, even if one is in UTF-8 and the other is in Windows 31J.

p ["foo".encode("UTF-8"), "bar".encode("CP932")].join
# Not raised.

However, if these strings contain a non-ASCII character, Encoding::CompatibilityError occurs.

p ["あ".encode("UTF-8"), "う".encode("CP932")].join
# => `join': incompatible character encodings: UTF-8 and Windows-31J (En
coding::CompatibilityError)

So, if one of the file paths and a cell value of the CSV have any non-ASCII character, the same exception may occur here.

I think that converting the file paths into UTF-8 may solve the problem.

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

No branches or pull requests

1 participant