Skip to content

on windows if folder name is utf8 string, File.directory? get wrong result #547

Open
tka opened this Issue Feb 24, 2013 · 3 comments

3 participants

@tka
tka commented Feb 24, 2013

JRuby 1.7.3 On windows 7

require 'fileutils' ;
FileUtils.mkdir 'test';
Dir.chdir('test');
FileUtils.mkdir('✓');
Dir.glob("*") do |x|
  p "#{x} - #{File.exist?(x)}"; 
  p File.directory?(x);
end

result with Ruby 1.9.3 mode irb

"\xC3\xA2\xC2\x9C\xC2\x93 - false"
false

result with Ruby 1.8.7 mode irb

"\342\234\223 - true"
SystemCallError: Unknown error - Unknown Error (20047) - C:/jruby-1.7.3/test/?
    from org/jruby/RubyFileTest.java:101:in `directory?'
    from org/jruby/RubyFileTest.java:86:in `directory?'
    from (irb):7:in `evaluate'
    from org/jruby/RubyDir.java:339:in `glob'
    from (irb):5:in `evaluate'
    from org/jruby/RubyKernel.java:1061:in `eval'
    from C:/jruby-1.7.3/lib/ruby/1.8/irb.rb:158:in `eval_input'
    from C:/jruby-1.7.3/lib/ruby/1.8/irb.rb:271:in `signal_status'
    from C:/jruby-1.7.3/lib/ruby/1.8/irb.rb:155:in `eval_input'
    from org/jruby/RubyKernel.java:1409:in `loop'
    from org/jruby/RubyKernel.java:1160:in `catch'
    from C:/jruby-1.7.3/lib/ruby/1.8/irb.rb:154:in `eval_input'
    from C:/jruby-1.7.3/lib/ruby/1.8/irb.rb:71:in `start'
    from org/jruby/RubyKernel.java:1160:in `catch'
    from C:/jruby-1.7.3/lib/ruby/1.8/irb.rb:70:in `start'
    from C:\jruby-1.7.3\/bin/jirb_swing:54:in `(root)'
@tka
tka commented Feb 24, 2013

in 1.9.3 mode if set Encoding.default_external='utf-8' and use force_encoding

Encoding.default_external='utf-8'
require 'fileutils' ;
FileUtils.mkdir 'test';
Dir.chdir('test');
FileUtils.mkdir('✓'.force_encoding('utf-8'));
Dir.glob("*") do |x|
  p "#{x} - #{File.exist?(x)}"; 
  p File.directory?(x);
end

reslut

"✓ - true"
SystemCallError: Unknown error - Unknown Error (20047) - C:/jruby-1.7.3/test/test/test/?
    from org/jruby/RubyFileTest.java:101:in `directory?'
    from org/jruby/RubyFileTest.java:86:in `directory?'
    from (irb):24:in `evaluate'
    from org/jruby/RubyDir.java:339:in `glob'
    from (irb):22:in `evaluate'
    from org/jruby/RubyKernel.java:1066:in `eval'
    from org/jruby/RubyKernel.java:1409:in `loop'
    from org/jruby/RubyKernel.java:1174:in `catch'
    from org/jruby/RubyKernel.java:1174:in `catch'
    from C:\jruby-1.7.3\/bin/jirb_swing:54:in `(root)'
@lolindrath

This appears to be fixed in JRuby 1.7.12 on Windows 7 x64, I think it can be closed.

If I run the example code I get:

C:\Users\Lolindrath\Downloads>jruby --1.9 547.rb
SyntaxError: 547.rb:6: invalid multibyte char (US-ASCII)

If I add # Encoding: utf-8 to the top of the file I get:

C:\Users\Lolindrath\Downloads>jruby --1.9 547.rb
"\xE2\x9C\x93 - false"
false

Which matches the example output from above for MRI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.