From aeeb84d98e148f4b4ff011e04ed752ee6c8e54bc Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Mon, 14 Mar 2011 08:57:02 +0100 Subject: [PATCH] fix Content Type handling with layout_engine --- CHANGES | 5 +++++ lib/sinatra/base.rb | 2 +- test/templates_test.rb | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 41fc1ed2..799ed65a 100644 --- a/CHANGES +++ b/CHANGES @@ -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 diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index 1e9aadce..c259b9da 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -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 diff --git a/test/templates_test.rb b/test/templates_test.rb index 119f3872..d5eb0d66 100644 --- a/test/templates_test.rb +++ b/test/templates_test.rb @@ -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 }