Issue #9016 has been updated by renatosilva (Renato Silva).

File encoding-lying-reduced.rb added

This reduced test case shows that the argument looks like an ISO-8859-1 string even though its encoding is reported as CP850.
----------------------------------------
Bug #9016: String#encoding is lying?
https://bugs.ruby-lang.org/issues/9016#change-42447

Author: renatosilva (Renato Silva)
Status: Feedback
Priority: Normal
Assignee: cruby-windows
Category: 
Target version: 
ruby -v: ruby 2.0.0p247 (2013-06-27) [i386-mingw32]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


Please see attached test case.

If you try opening a file using a CP850 (possibly others) path which was passed as command line argument, you are not able at all, unless you encode the argument into its very own reported encoding (CP850), and from some encoding different than that (in my case, both ISO-8859-1 and Windows-1252 worked). It is just like ARGV[0].encoding is lying!

Before, in Ruby 1.8, File.open would work just fine. I have a script that just stopped working, till I found the above workaround. This seems to me like a bug. I would expect Ruby to just do its best in order to convert user input into the required encodings for file APIs and such. Meaning I would not like for a possible fix to require any code migration from 1.8 to 1.9+ at all.


-- 
http://bugs.ruby-lang.org/