JRuby File and Dir cant using non ascii path


#1

Hi all
i have already put a issue on jira
http://jira.codehaus.org/browse/JRUBY-3168?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

file = File.open(“D:\我的文件test.txt”)
file.each() do |line|
puts line # can print the content in the test.txt
end
puts file.path # print D:???\test.txt

is there anyway to solve it? or shoud i set something?
and this makes my netbeans cant create project under non-ascii folder(it
shows cant find rake tasks).

thanks.

koji


#2

hi all
i tried to patch, but dont know it will make some side effect or not…
In org.jruy.RubyDir.java#line 250
String adjustedPath = RubyFile.adjustRootPathOnWindows(
recv.getRuntime(), path.toString(), null);
change to
String adjustedPath = RubyFile.adjustRootPathOnWindows(
recv.getRuntime(), path.getUnicodeValue().toString(),
null);

makes Dir.chdir can work.

and RubyFile.java
#line 631
return context.getRuntime().newString(path);
change to
return RubyString.newUnicodeString(context.getRuntime(), path);

dont know its good or not.

koji

2008/11/25 koji Lin removed_email_address@domain.invalid


#3

Hi koji

JRuby goes well with the patch posted by Takai-san on
http://jira.codehaus.org/browse/JRUBY-2812 .

My environment is:

Windows XP(JP),file.encoding == MS932(cp932,Windows-31J)

This is the test code.

file = File.open(“C:\Pool\日本語test.txt”)
file.each do |line|
puts line
end

C:\Pool>jruby test.rb
あ
い
う
え
お

Here is a patch for the current trunk.
Please try this.


Index: src/org/jruby/RubyString.java

— src/org/jruby/RubyString.java (revision 8168)
+++ src/org/jruby/RubyString.java (working copy)
@@ -3814,6 +3814,14 @@
}
}

  • public String getFileEncodingValue() {
  •    try {
    
  •        return new String(value.bytes,value.begin,value.realSize, 
    

System.getProperty(“file.encoding”));

  •    } catch (Exception e) {
    
  •        throw new RuntimeException("Something's seriously broken 
    

with encodings", e);

  •    }
    
  • }
  • @Override
    public IRubyObject to_java() {
    return MiniJava.javaToRuby(getRuntime(), new
    String(getBytes()));
    Index: src/org/jruby/RubyFile.java
    ===================================================================
    — src/org/jruby/RubyFile.java (revision 8168)
    +++ src/org/jruby/RubyFile.java (working copy)
    @@ -416,7 +416,7 @@
    IRubyObject filename = args[0].convertToString();
    getRuntime().checkSafeString(filename);
  •    path = filename.convertToString().getUnicodeValue();
    
  •    path = filename.convertToString().getFileEncodingValue();
    
      String modeString;
      ModeFlags modes;
    

removed_email_address@domain.invalid
koji Lin removed_email_address@domain.invalid wrote:

hi all
i tried to patch, but dont know it will make some side effect or not…
In org.jruy.RubyDir.java
#line 250
String adjustedPath = RubyFile.adjustRootPathOnWindows(
recv.getRuntime(), path.toString(), null);
change to
String adjustedPath = RubyFile.adjustRootPathOnWindows(
recv.getRuntime(), path.getUnicodeValue().toString(), null);

makes Dir.chdir can work.

and RubyFile.java
#line 631
return context.getRuntime().newString(path);
change to
return RubyString.newUnicodeString(context.getRuntime(), path);

dont know its good or not.

koji

2008/11/25 koji Lin removed_email_address@domain.invalid

Hi all
i have already put a issue on jira
http://jira.codehaus.org/browse/JRUBY-3168?page=
com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
file = File.open("D:\\我的文件test.txt")
file.each() do |line|
  puts line # can print the content in the test.txt
end
puts file.path # print D:????\test.txt
is there anyway to solve it? or shoud i set something?
and this makes my netbeans cant create project under non-ascii folder(it shows cant find rake
tasks).
thanks.
koji


koichiro removed_email_address@domain.invalid


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email