Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Duplicate
-
Affects Version/s: JRuby 1.6.4
-
Fix Version/s: None
-
Component/s: Encoding
-
Labels:None
-
Environment:Windows 7
-
Number of attachments :
Description
I.e.: the code:
org.jruby.RubyFileTest.directory_p(ThreadContext, IRubyObject), which does:
runtime.getPosix().stat(file.getAbsolutePath()).isDirectory()
"No such file or directory" error is thrown.
Internally it does something as LibC.stat(path, fileStat), and apparently the problem is that the LibC.stat is not converting the java string to the filesystem encoding properly (note: my guess is that in windows it needs to be converted to the mbcs encoding, while in Linux the string can probably be used as is because it's an utf-8 string).
The code below reproduces the error in the same way that org.jruby.RubyFileTest.directory_p(ThreadContext, IRubyObject) does (but in a proper test-case).
import java.io.File; import junit.framework.TestCase; import org.jruby.Ruby; import org.jruby.RubyFile; import org.jruby.RubyString; import org.jruby.util.JRubyFile; /** * @author Fabio */ public class UnicodeCharsJRubyTest extends TestCase { public void testUnicodeChars() throws Exception { File file = new File("unicodeáéíóú"); if (file.exists()) { if (!file.delete()) { fail("Unable to delete file: " + file); } } try { if (!file.mkdirs()) { fail("Unable to create directory: " + file); } Ruby runtime = Ruby.newInstance(); JRubyFile rubyFile = RubyFile.file(RubyString.newString(runtime, file.getAbsolutePath())); assertTrue(rubyFile.exists()); assertTrue(file.exists()); assertTrue(file.isDirectory()); try { assertTrue(runtime.getPosix().stat(rubyFile.getAbsolutePath()).isDirectory()); } catch (Exception e) { throw new RuntimeException("Expecting posix layer to work properly", e); } } finally { if (file.exists()) { file.delete(); } } } }
Issue Links
- duplicates
-
JRUBY-3379
Windows file encoding issue - unicode characters like æ ø å
-
Duplicate of JRUBY-3379.