ruby-changes:21476
From: nobu <ko1@a...>
Date: Wed, 26 Oct 2011 15:26:29 +0900 (JST)
Subject: [ruby-changes:21476] nobu:r33525 (trunk): * file.c (rb_file_join): honor input encodings than ASCII-8BIT.
nobu 2011-10-26 15:24:29 +0900 (Wed, 26 Oct 2011) New Revision: 33525 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33525 Log: * file.c (rb_file_join): honor input encodings than ASCII-8BIT. [ruby-core:40338] [Bug #5483] Modified files: trunk/ChangeLog trunk/file.c trunk/test/ruby/test_path.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 33524) +++ ChangeLog (revision 33525) @@ -1,3 +1,8 @@ +Wed Oct 26 15:24:25 2011 Nobuyoshi Nakada <nobu@r...> + + * file.c (rb_file_join): honor input encodings than ASCII-8BIT. + [ruby-core:40338] [Bug #5483] + Tue Oct 25 21:52:31 2011 Tanaka Akira <akr@f...> * include/ruby/defines.h: use "__sparc" instead of "sparc" and Index: test/ruby/test_path.rb =================================================================== --- test/ruby/test_path.rb (revision 33524) +++ test/ruby/test_path.rb (revision 33525) @@ -247,4 +247,13 @@ assert_raise(Encoding::CompatibilityError) {open(s.encode("utf-32be"))} assert_raise(Encoding::CompatibilityError) {open(s.encode("utf-32le"))} end + + def test_join + bug5483 = '[ruby-core:40338]' + path = %w[a b] + Encoding.list.each do |e| + next unless e.ascii_compatible? + assert_equal(e, File.join(*path.map {|s| s.force_encoding(e)}).encoding, bug5483) + end + end end Index: file.c =================================================================== --- file.c (revision 33524) +++ file.c (revision 33525) @@ -3847,7 +3847,10 @@ FilePathStringValue(tmp); } name = StringValueCStr(result); - if (i > 0 && !NIL_P(sep)) { + if (i == 0) { + rb_enc_copy(result, tmp); + } + else if (!NIL_P(sep)) { tail = chompdirsep(name); if (RSTRING_PTR(tmp) && isdirsep(RSTRING_PTR(tmp)[0])) { rb_str_set_len(result, tail - name); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/