Skip to content

Commit 4c99202

Browse files
martinemdedeivid-rodriguez
authored andcommitted
Merge pull request #6947 from negi0109/fix-extract-symlink-dir
(cherry picked from commit 13e19b3)
1 parent a737f55 commit 4c99202

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/rubygems/package.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,8 @@ def extract_files(destination_dir, pattern = "*")
413413
# extracted.
414414

415415
def extract_tar_gz(io, destination_dir, pattern = "*") # :nodoc:
416+
destination_dir = File.realpath(destination_dir)
417+
416418
directories = []
417419
symlinks = []
418420

test/rubygems/test_gem_package.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,32 @@ def test_extract_tar_gz_symlink_relative_path
573573
File.read(extracted)
574574
end
575575

576+
def test_extract_symlink_into_symlink_dir
577+
package = Gem::Package.new @gem
578+
tgz_io = util_tar_gz do |tar|
579+
tar.mkdir "lib", 0o755
580+
tar.add_symlink "lib/link", "./inside.rb", 0o644
581+
tar.add_file "lib/inside.rb", 0o644 do |io|
582+
io.write "hi"
583+
end
584+
end
585+
586+
destination_subdir = File.join @destination, "subdir"
587+
FileUtils.mkdir_p destination_subdir
588+
589+
destination_linkdir = File.join @destination, "linkdir"
590+
File.symlink(destination_subdir, destination_linkdir)
591+
592+
package.extract_tar_gz tgz_io, destination_linkdir
593+
594+
extracted = File.join destination_subdir, "lib/link"
595+
assert_path_exist extracted
596+
assert_equal "./inside.rb",
597+
File.readlink(extracted)
598+
assert_equal "hi",
599+
File.read(extracted)
600+
end
601+
576602
def test_extract_tar_gz_symlink_broken_relative_path
577603
package = Gem::Package.new @gem
578604
package.verify

0 commit comments

Comments
 (0)