1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

fix Content Type handling with layout_engine

This commit is contained in:
Konstantin Haase 2011-03-14 08:57:02 +01:00
parent 87bdb85ff1
commit aeeb84d98e
3 changed files with 14 additions and 1 deletions

View file

@ -3,6 +3,11 @@
* Use a generated session secret when using `enable :sessions`. (Konstantin
Haase)
* Fixed a bug where the wrong content type was used if no content type was
set and a template engine was used with a different engine for the layout
with different default content types, say Less embedded in Slim.
(Konstantin Haase)
= 1.2.0 / 2011-03-03
* Added `slim` rendering method for rendering Slim templates. (Steve

View file

@ -542,7 +542,7 @@ module Sinatra
# render layout
if layout
options = options.merge(:views => views, :layout => false, :eat_errors => eat_errors, :scope => scope)
catch(:layout_missing) { output = render(layout_engine, layout, options, locals) { output }}
catch(:layout_missing) { return render(layout_engine, layout, options, locals) { output } }
end
output.extend(ContentTyped).content_type = content_type if content_type

View file

@ -224,6 +224,14 @@ class TemplatesTest < Test::Unit::TestCase
assert_equal "Hello <%= 'World' %>!", body
end
it "does not leak the content type to the template" do
render_app :str => { :layout_engine => :erb } do
settings.template(:layout) { 'Hello <%= yield %>!' }
render :str, "<%= 'World' %>", :content_type => :txt
end
assert_equal "text/html;charset=utf-8", headers['Content-Type']
end
it "is possible to register another template" do
Tilt.register "html.erb", Tilt[:erb]
render_app { render :erb, :calc }