Permalink
Browse files

Merge pull request #13168 from acapilleri/format_localized_template_4…

…_0_stable

Fix header Content-Type: #<Mime::NullType:...> in localized template
  • Loading branch information...
2 parents 7b4e8f2 + 2c97d32 commit 4fdc1565a17139e9dca01649156752a760099127 @guilleiguaran guilleiguaran committed Dec 4, 2013
View
@@ -1,3 +1,12 @@
+* Fix header `Content-Type: #<Mime::NullType:...>` in localized template.
+
+ When localized template has no format in the template name,
+ the response now has the default and correct `content-type`.
+
+ Fixes #13064.
+
+ *Angelo Capilleri*
+
* Fix regression with `simple_format` not having access to the `raw` method
when included in isolation, introduced with the security fix in Rails 4.0.2.
@@ -14,7 +14,7 @@ def process_action(*) #:nodoc:
def render(*args) #:nodoc:
raise ::AbstractController::DoubleRenderError if response_body
super
- self.content_type ||= Mime[lookup_context.rendered_format].to_s
+ _process_format(lookup_context.rendered_format)
response_body
end
@@ -35,6 +35,11 @@ def render_to_body(*)
private
+ def _process_format(format)
+ # format is a Mime::NullType instance here then this condition can't be changed to `if format`
+ self.content_type ||= Mime[format] unless format.nil?
+ end
+
# Normalize arguments by catching blocks and setting them on :update.
def _normalize_args(action=nil, options={}, &blk) #:nodoc:
options = super
@@ -34,4 +34,15 @@ def test_use_fallback_locales
get :hello_world
assert_equal "Gutten Tag", @response.body
end
+
+ def test_localized_template_has_correct_header_with_no_format_in_template_name
+ old_locale = I18n.locale
+ I18n.locale = :it
+
+ get :hello_world
+ assert_equal "Ciao Mondo", @response.body
+ assert_equal "text/html", @response.content_type
+ ensure
+ I18n.locale = old_locale
+ end
end
@@ -0,0 +1 @@
+Ciao Mondo

0 comments on commit 4fdc156

Please sign in to comment.