diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-07-20 03:27:59 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-07-20 03:27:59 +0000 |
commit | 878384483d99fd4b887c5ddf44765b4178e72e42 (patch) | |
tree | 12a790b28d34fb35e5406846d4624f6e1ca06f38 | |
parent | b698066bbd6a760658a38971958adf08f0ec685c (diff) | |
download | ruby-878384483d99fd4b887c5ddf44765b4178e72e42.tar.gz |
* lib/fileutils.rb (FileUtils::Entry_#copy): check file name
spearator boundary. [ruby-core:31360]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28685 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/fileutils.rb | 13 | ||||
-rw-r--r-- | test/fileutils/test_fileutils.rb | 9 |
3 files changed, 26 insertions, 1 deletions
@@ -1,3 +1,8 @@ +Tue Jul 20 12:27:56 2010 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * lib/fileutils.rb (FileUtils::Entry_#copy): check file name + spearator boundary. [ruby-core:31360] + Mon Jul 19 18:34:12 2010 Tanaka Akira <akr@fsij.org> * ext/pathname/pathname.c (get_strpath): check the type. diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 5905022c96..73e2bfe3c3 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -1240,7 +1240,7 @@ module FileUtils 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 @@ module FileUtils 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: diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb index f385589d0a..494204ced5 100644 --- a/test/fileutils/test_fileutils.rb +++ b/test/fileutils/test_fileutils.rb @@ -286,6 +286,15 @@ class TestFileUtils 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 |