aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG.md9
-rw-r--r--actionpack/lib/action_controller/metal/rendering.rb3
-rw-r--r--actionpack/lib/action_dispatch/http/mime_type.rb5
-rw-r--r--actionpack/test/controller/localized_templates_test.rb11
-rw-r--r--actionpack/test/fixtures/localized/hello_world.it.erb1
5 files changed, 27 insertions, 2 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index cfefeb23ce..8181b386be 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -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*
+
* Try to escape each part of a url correctly when using a redirect route.
Fixes #13110.
diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb
index 5c48b4ab98..66d34f3b67 100644
--- a/actionpack/lib/action_controller/metal/rendering.rb
+++ b/actionpack/lib/action_controller/metal/rendering.rb
@@ -34,7 +34,8 @@ module ActionController
def _process_format(format)
super
- self.content_type ||= format.to_s
+ # format is a Mime::NullType instance here then this condition can't be changed to `if format`
+ self.content_type ||= format.to_s unless format.nil?
end
# Normalize arguments by catching blocks and setting them on :update.
diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb
index c92d997a5c..a398919ca7 100644
--- a/actionpack/lib/action_dispatch/http/mime_type.rb
+++ b/actionpack/lib/action_dispatch/http/mime_type.rb
@@ -1,4 +1,5 @@
require 'set'
+require 'singleton'
require 'active_support/core_ext/module/attribute_accessors'
require 'active_support/core_ext/string/starts_ends_with'
@@ -27,7 +28,7 @@ module Mime
class << self
def [](type)
return type if type.is_a?(Type)
- Type.lookup_by_extension(type) || NullType.new
+ Type.lookup_by_extension(type) || NullType.instance
end
def fetch(type)
@@ -292,6 +293,8 @@ module Mime
end
class NullType
+ include Singleton
+
def nil?
true
end
diff --git a/actionpack/test/controller/localized_templates_test.rb b/actionpack/test/controller/localized_templates_test.rb
index 6b02eedaed..c95ef8a0c7 100644
--- a/actionpack/test/controller/localized_templates_test.rb
+++ b/actionpack/test/controller/localized_templates_test.rb
@@ -34,4 +34,15 @@ class LocalizedTemplatesTest < ActionController::TestCase
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
diff --git a/actionpack/test/fixtures/localized/hello_world.it.erb b/actionpack/test/fixtures/localized/hello_world.it.erb
new file mode 100644
index 0000000000..9191fdc187
--- /dev/null
+++ b/actionpack/test/fixtures/localized/hello_world.it.erb
@@ -0,0 +1 @@
+Ciao Mondo \ No newline at end of file