From f9ac2106bf0835c836bd48e82680908f5dfab233 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 2 Sep 2015 07:58:24 +0000 Subject: file.c: use filesystem encoding * file.c (rb_realpath_internal): use filesystem encoding if the argument is in ASCII encodings. * win32/file.c (rb_readlink): needs the result encoding. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51738 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_file.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_file.rb b/test/ruby/test_file.rb index 8335b78760..d7507b4661 100644 --- a/test/ruby/test_file.rb +++ b/test/ruby/test_file.rb @@ -258,6 +258,26 @@ class TestFile < Test::Unit::TestCase } end + def test_realpath_encoding + fsenc = Encoding.find("filesystem") + nonascii = "\u{0391 0410 0531 10A0 05d0 2C00 3042}" + tst = "A" + nonascii.each_char {|c| tst << c.encode(fsenc) rescue nil} + Dir.mktmpdir('rubytest-realpath') {|tmpdir| + realdir = File.realpath(tmpdir) + open(File.join(tmpdir, tst), "w") {} + a = File.join(tmpdir, "a") + File.symlink(tst, a) + assert_equal(File.join(realdir, tst), File.realpath(a)) + File.unlink(a) + + tst = "A" + nonascii + open(File.join(tmpdir, tst), "w") {} + File.symlink(tst, a) + assert_equal(File.join(realdir, tst), File.realpath(a.encode("UTF-8"))) + } + end + def test_realdirpath Dir.mktmpdir('rubytest-realdirpath') {|tmpdir| realdir = File.realpath(tmpdir) -- cgit v1.2.3