提交 7b1a6c3c 编写于 作者: A Andrew White

Use Dir.glob in find_root_with_flag to return correct case

As of Ruby 2.2, Dir.glob returns matches with the correct case as opposed
to in previous versions where the matches were returned with the case of
the pattern. In certain scenarios on Mac OS X the app can be booted with
the incorrect case, e.g. incorrect case on Pow symlink). This is because
the app is built by Rack::Builder evaluating a string from the config.ru
file and passing the incorrectly cased path to the eval method.

As Dir.glob is the only method in Ruby 2.2 that appears to do this case
correction currently we need to rewrite the find_root_with_flag method
to use it so that it corrects the case for when the applications paths
instance is created.

Fixes #18660.
上级 c99bea1d
......@@ -73,7 +73,7 @@ def helper_attr(*attrs)
# Provides a proxy to access helpers methods from outside the view.
def helpers
@helper_proxy ||= begin
@helper_proxy ||= begin
proxy = ActionView::Base.new
proxy.config = config.inheritable_copy
proxy.extend(_helpers)
......
* Use Dir.glob in `find_root_with_flag` so that correct case is used on Mac OS X.
Fixes #18660.
*Andrew White*
## Rails 4.2.1 (March 19, 2015) ##
* Add a new-line to the end of route method generated code.
......
......@@ -663,16 +663,20 @@ def has_migrations? #:nodoc:
end
def self.find_root_with_flag(flag, root_path, default=nil) #:nodoc:
root_paths = [File.join(root_path, flag)]
while root_path && File.directory?(root_path) && !File.exist?("#{root_path}/#{flag}")
parent = File.dirname(root_path)
root_path = parent != root_path && parent
while root_path != (root_path = File.dirname(root_path))
root_paths << File.join(root_path, flag)
end
root = File.exist?("#{root_path}/#{flag}") ? root_path : default
matches = Dir.glob(root_paths, File::FNM_CASEFOLD)
matches.sort_by!(&:size)
match = matches.last
root = match ? File.dirname(match) : default
raise "Could not find root path for #{self}" unless root
Pathname.new File.realpath root
Pathname.new(File.realpath(root))
end
def default_middleware_stack #:nodoc:
......
......@@ -40,4 +40,38 @@ def teardown
assert_equal 'UTC', Rails.application.config.time_zone
end
end
class CaseInsensitiveRackupTest < ActiveSupport::TestCase
include ActiveSupport::Testing::Isolation
def app_path(*args)
tmp_path(*%w[OtherApp] + args)
end
def rackup
require "rack"
app, _ = Rack::Builder.parse_file("#{app_path.downcase}/config.ru")
app
end
def setup
build_app
boot_rails
end
def teardown
teardown_app
end
test "rails app is present" do
assert File.exist?(app_path("config"))
end
test "config.ru can be racked up" do
Dir.chdir app_path do
@app = rackup
assert_welcome get("/")
end
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册