From c23a7895f2e8bf29fadde2ea74b6bcdba998bf2a Mon Sep 17 00:00:00 2001
From: David Fifield <david@bamsoftware.com>
Date: Wed, 13 Sep 2017 21:36:33 -0700
Subject: [PATCH] Add test_install_location_suffix.

This tests for the case where install_location resolves a location that
has destination_dir as a prefix, but is not within destination_dir.

Example:
	install_location "../extractsuffix.rb", "/tmp/extract"
should raise PathError, not return
	"/tmp/extractsuffix.rb"
---
 test/rubygems/test_gem_package.rb | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/test/rubygems/test_gem_package.rb b/test/rubygems/test_gem_package.rb
index cec1981c..844f2b67 100644
--- a/test/rubygems/test_gem_package.rb
+++ b/test/rubygems/test_gem_package.rb
@@ -566,6 +566,21 @@ class TestGemPackage < Gem::Package::TarTestCase
                  "#{@destination} is not allowed", e.message)
   end
 
+  def test_install_location_suffix
+    package = Gem::Package.new @gem
+
+    filename = "../#{File.basename(@destination)}suffix.rb"
+
+    e = assert_raises Gem::Package::PathError do
+      package.install_location filename, @destination
+    end
+
+    parent = File.expand_path File.join @destination, filename
+
+    assert_equal("installing into parent path #{parent} of " +
+                 "#{@destination} is not allowed", e.message)
+  end
+
   def test_load_spec
     entry = StringIO.new Gem.gzip @spec.to_yaml
     def entry.full_name() 'metadata.gz' end
-- 
2.18.0

