Skip to content

Commit

Permalink
Template without a known template handler should only be reachable th…
Browse files Browse the repository at this point in the history
…rough its exact path. [#2027 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information
thedarkone authored and josh committed Feb 24, 2009
1 parent b35562f commit 85df484
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
23 changes: 15 additions & 8 deletions actionpack/lib/action_view/template.rb
Expand Up @@ -103,12 +103,12 @@ def self.exempt_from_layout(*extensions)
@@exempt_from_layout.merge(regexps)
end

attr_accessor :filename, :load_path, :base_path
attr_accessor :template_path, :filename, :load_path, :base_path
attr_accessor :locale, :name, :format, :extension
delegate :to_s, :to => :path

def initialize(template_path, load_path)
template_path = template_path.dup
@template_path = template_path.dup
@load_path, @filename = load_path, File.join(load_path, template_path)
@base_path, @name, @locale, @format, @extension = split(template_path)
@base_path.to_s.gsub!(/\/$/, '') # Push to split method
Expand All @@ -119,13 +119,20 @@ def initialize(template_path, load_path)

def accessible_paths
paths = []
paths << path
paths << path_without_extension
if multipart?
formats = format.split(".")
paths << "#{path_without_format_and_extension}.#{formats.first}"
paths << "#{path_without_format_and_extension}.#{formats.second}"

if valid_extension?(extension)
paths << path
paths << path_without_extension
if multipart?
formats = format.split(".")
paths << "#{path_without_format_and_extension}.#{formats.first}"
paths << "#{path_without_format_and_extension}.#{formats.second}"
end
else
# template without explicit template handler should only be reachable through its exact path
paths << template_path
end

paths
end

Expand Down
10 changes: 10 additions & 0 deletions actionpack/test/template/render_test.rb
Expand Up @@ -224,6 +224,16 @@ def test_render_legacy_handler_with_custom_type
assert_equal 'source: Hello, <%= name %>!; locals: {:name=>"Josh"}', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo)
end

def test_render_ignores_templates_with_malformed_template_handlers
%w(malformed malformed.erb malformed.html.erb malformed.en.html.erb).each do |name|
assert_raise(ActionView::MissingTemplate) { @view.render(:file => "test/malformed/#{name}") }
end
end

def test_template_with_malformed_template_handler_is_reachable_trough_its_exact_filename
assert_equal "Don't render me!", @view.render(:file => 'test/malformed/malformed.html.erb~')
end

def test_render_with_layout
assert_equal %(<title></title>\nHello world!\n),
@view.render(:file => "test/hello_world.erb", :layout => "layouts/yield")
Expand Down

0 comments on commit 85df484

Please sign in to comment.