Forum: JRuby JRuby File and Dir cant using non ascii path

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B0384f0e49f2129f5b6bda8ae0b390c0?d=identicon&s=25 koji Lin (Guest)
on 2008-11-25 09:13
(Received via mailing list)
Hi all
i have already put a issue on jira
http://jira.codehaus.org/browse/JRUBY-3168?page=co...

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
B0384f0e49f2129f5b6bda8ae0b390c0?d=identicon&s=25 koji Lin (Guest)
on 2008-11-26 04:43
(Received via mailing list)
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 <koji.lin@gmail.com>
1ce18b10bd8f911566c5577042b6a44c?d=identicon&s=25 Koichiro Ohba (Guest)
on 2008-11-27 13:07
(Received via mailing list)
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;

--------------------------------------------------------------------


>>>>> <747e82370811251942g3a5cfff0ie73dfd96896d6b22@mail.gmail.com>
>>>>>  koji Lin <koji.lin@gmail.com> 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 <koji.lin@gmail.com>

>     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 <koichiro@meadowy.org>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
This topic is locked and can not be replied to.