ruby-changes:16747
From: yugui <ko1@a...>
Date: Sat, 24 Jul 2010 19:38:34 +0900 (JST)
Subject: [ruby-changes:16747] Ruby:r28743 (ruby_1_9_2): merges r28685 from trunk into ruby_1_9_2.
yugui 2010-07-24 19:38:16 +0900 (Sat, 24 Jul 2010) New Revision: 28743 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=28743 Log: merges r28685 from trunk into ruby_1_9_2. -- * lib/fileutils.rb (FileUtils::Entry_#copy): check file name spearator boundary. [ruby-core:31360] Modified files: branches/ruby_1_9_2/ChangeLog branches/ruby_1_9_2/lib/fileutils.rb branches/ruby_1_9_2/test/fileutils/test_fileutils.rb Index: ruby_1_9_2/ChangeLog =================================================================== --- ruby_1_9_2/ChangeLog (revision 28742) +++ ruby_1_9_2/ChangeLog (revision 28743) @@ -1,3 +1,8 @@ +Tue Jul 20 12:27:56 2010 Nobuyoshi Nakada <nobu@r...> + + * lib/fileutils.rb (FileUtils::Entry_#copy): check file name + spearator boundary. [ruby-core:31360] + Mon Jul 19 09:00:58 2010 Nobuyoshi Nakada <nobu@r...> * NEWS (Kernel#instance_eval): add an incompatible change since Index: ruby_1_9_2/lib/fileutils.rb =================================================================== --- ruby_1_9_2/lib/fileutils.rb (revision 28742) +++ ruby_1_9_2/lib/fileutils.rb (revision 28743) @@ -1240,7 +1240,7 @@ when file? copy_file dest when directory? - if !File.exist?(dest) and /^#{Regexp.quote(path)}/ =~ File.dirname(dest) + if !File.exist?(dest) and descendant_diretory?(dest, path) raise ArgumentError, "cannot copy directory %s to itself %s" % [path, dest] end begin @@ -1394,6 +1394,17 @@ return File.path(base) if not dir or dir == '.' File.join(dir, base) end + + if File::ALT_SEPARATOR + DIRECTORY_TERM = "(?=[/#{Regexp.quote(File::ALT_SEPARATOR)}]|\\z)".freeze + else + DIRECTORY_TERM = "(?=/|\\z)".freeze + end + SYSCASE = File::FNM_SYSCASE.nonzero? ? "-i" : "" + + def descendant_diretory?(descendant, ascendant) + /\A(?#{SYSCASE}:#{Regexp.quote(ascendant)})#{DIRECTORY_TERM}/ =~ File.dirname(descendant) + end end # class Entry_ def fu_list(arg) #:nodoc: Index: ruby_1_9_2/test/fileutils/test_fileutils.rb =================================================================== --- ruby_1_9_2/test/fileutils/test_fileutils.rb (revision 28742) +++ ruby_1_9_2/test/fileutils/test_fileutils.rb (revision 28743) @@ -286,6 +286,15 @@ assert_directory 'tmp/cpr_dest/d' my_rm_rf 'tmp/cpr_src' my_rm_rf 'tmp/cpr_dest' + + bug3588 = '[ruby-core:31360]' + assert_nothing_raised(ArgumentError, bug3588) do + cp_r 'tmp', 'tmp2' + end + assert_directory 'tmp2/tmp' + assert_raise(ArgumentError, bug3588) do + cp_r 'tmp2', 'tmp2/new_tmp2' + end end def test_cp_r_symlink -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/