aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorAndrew White <pixeltrix@users.noreply.github.com>2017-03-30 06:26:25 +0100
committerGitHub <noreply@github.com>2017-03-30 06:26:25 +0100
commit51aa5b04c6e6f0b76bf86dbf84ad1e8744569aa0 (patch)
tree76c1f03aa5c16c65363c30e2a65aa44925bf9719 /railties
parentd5a2e8baa924ba6194ad4e6ae118b4d1ca19c342 (diff)
parentad44d7a054f3897154d5c275ddecade4032d0d54 (diff)
downloadrails-51aa5b04c6e6f0b76bf86dbf84ad1e8744569aa0.tar.gz
rails-51aa5b04c6e6f0b76bf86dbf84ad1e8744569aa0.tar.bz2
rails-51aa5b04c6e6f0b76bf86dbf84ad1e8744569aa0.zip
Merge pull request #28417 from schneems/schneems/symlink-failures
Raise when using a bad symlink
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/paths.rb9
-rw-r--r--railties/test/paths_test.rb20
2 files changed, 28 insertions, 1 deletions
diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb
index af3be10a31..6bdb673215 100644
--- a/railties/lib/rails/paths.rb
+++ b/railties/lib/rails/paths.rb
@@ -205,7 +205,14 @@ module Rails
# Returns all expanded paths but only if they exist in the filesystem.
def existent
- expanded.select { |f| File.exist?(f) }
+ expanded.select do |f|
+ does_exist = File.exist?(f)
+
+ if !does_exist && File.symlink?(f)
+ raise "File #{f.inspect} is a symlink that does not point to a valid file"
+ end
+ does_exist
+ end
end
def existent_directories
diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb
index 7b2551062a..f3db0a51d2 100644
--- a/railties/test/paths_test.rb
+++ b/railties/test/paths_test.rb
@@ -274,3 +274,23 @@ class PathsTest < ActiveSupport::TestCase
end
end
end
+
+class PathsIntegrationTest < ActiveSupport::TestCase
+ test "A failed symlink is still a valid file" do
+ Dir.mktmpdir do |dir|
+ Dir.chdir(dir) do
+ FileUtils.mkdir_p("foo")
+ File.symlink("foo/doesnotexist.rb", "foo/bar.rb")
+ assert_equal true, File.symlink?("foo/bar.rb")
+
+ root = Rails::Paths::Root.new("foo")
+ root.add "bar.rb"
+
+ exception = assert_raises(RuntimeError) do
+ root["bar.rb"].existent
+ end
+ assert_match File.expand_path("foo/bar.rb"), exception.message
+ end
+ end
+ end
+end