mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Do not allow templates coming from Fallback resolvers to store a virtual path.
This commit is contained in:
parent
682368d4ba
commit
5ec27189b8
5 changed files with 29 additions and 4 deletions
|
@ -57,6 +57,7 @@ module ActionView
|
|||
autoload :Resolver
|
||||
autoload :PathResolver
|
||||
autoload :FileSystemResolver
|
||||
autoload :FallbackFileSystemResolver
|
||||
end
|
||||
|
||||
autoload_at "action_view/template/error" do
|
||||
|
|
|
@ -10,7 +10,7 @@ module ActionView
|
|||
# this key is generated just once during the request, it speeds up all cache accesses.
|
||||
class LookupContext #:nodoc:
|
||||
mattr_accessor :fallbacks
|
||||
@@fallbacks = [FileSystemResolver.new(""), FileSystemResolver.new("/")]
|
||||
@@fallbacks = FallbackFileSystemResolver.instances
|
||||
|
||||
mattr_accessor :registered_details
|
||||
self.registered_details = []
|
||||
|
|
|
@ -135,6 +135,7 @@ module ActionView
|
|||
end
|
||||
end
|
||||
|
||||
# A resolver that loads files from the filesystem.
|
||||
class FileSystemResolver < PathResolver
|
||||
def initialize(path)
|
||||
raise ArgumentError, "path already is a Resolver class" if path.is_a?(Resolver)
|
||||
|
@ -152,4 +153,16 @@ module ActionView
|
|||
end
|
||||
alias :== :eql?
|
||||
end
|
||||
|
||||
# The same as FileSystemResolver but does not allow templates to store
|
||||
# a virtual path since it is invalid for such resolvers.
|
||||
class FallbackFileSystemResolver < FileSystemResolver
|
||||
def self.instances
|
||||
[new(""), new("/")]
|
||||
end
|
||||
|
||||
def decorate(*)
|
||||
super.each { |t| t.virtual_path = nil }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -100,8 +100,8 @@ class LookupContextTest < ActiveSupport::TestCase
|
|||
|
||||
@lookup_context.with_fallbacks do
|
||||
assert_equal 3, @lookup_context.view_paths.size
|
||||
assert @lookup_context.view_paths.include?(ActionView::FileSystemResolver.new(""))
|
||||
assert @lookup_context.view_paths.include?(ActionView::FileSystemResolver.new("/"))
|
||||
assert @lookup_context.view_paths.include?(ActionView::FallbackFileSystemResolver.new(""))
|
||||
assert @lookup_context.view_paths.include?(ActionView::FallbackFileSystemResolver.new("/"))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -114,7 +114,7 @@ module RenderTestCases
|
|||
end
|
||||
|
||||
def test_render_sub_template_with_errors
|
||||
@view.render(:file => "test/sub_template_raise")
|
||||
@view.render(:template => "test/sub_template_raise")
|
||||
flunk "Render did not raise Template::Error"
|
||||
rescue ActionView::Template::Error => e
|
||||
assert_match %r!method.*doesnt_exist!, e.message
|
||||
|
@ -123,6 +123,17 @@ module RenderTestCases
|
|||
assert_equal File.expand_path("#{FIXTURE_LOAD_PATH}/test/_raise.html.erb"), e.file_name
|
||||
end
|
||||
|
||||
def test_render_file_with_errors
|
||||
@view.render(:file => File.expand_path("test/_raise", FIXTURE_LOAD_PATH))
|
||||
flunk "Render did not raise Template::Error"
|
||||
rescue ActionView::Template::Error => e
|
||||
assert_match %r!method.*doesnt_exist!, e.message
|
||||
assert_equal "", e.sub_template_message
|
||||
assert_equal "1", e.line_number
|
||||
assert_equal "1: <%= doesnt_exist %>", e.annoted_source_code.strip
|
||||
assert_equal File.expand_path("#{FIXTURE_LOAD_PATH}/test/_raise.html.erb"), e.file_name
|
||||
end
|
||||
|
||||
def test_render_object
|
||||
assert_equal "Hello: david", @view.render(:partial => "test/customer", :object => Customer.new("david"))
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue