Use default charset when we read content type without charset.

This commit is contained in:
kennyj
2011-12-07 01:46:41 +09:00
parent 9be2353fac
commit a1986e7d55
2 changed files with 12 additions and 1 deletions

View File

@@ -69,7 +69,7 @@ module ActionDispatch # :nodoc:
if content_type = self["Content-Type"]
type, charset = content_type.split(/;\s*charset=/)
@content_type = Mime::Type.lookup(type)
@charset = charset || "UTF-8"
@charset = charset || self.class.default_charset
end
prepare_cache_control!

View File

@@ -130,6 +130,17 @@ class ResponseTest < ActiveSupport::TestCase
assert_equal('application/xml; charset=utf-16', resp.headers['Content-Type'])
end
test "read content type without charset" do
original = ActionDispatch::Response.default_charset
begin
ActionDispatch::Response.default_charset = 'utf-16'
resp = ActionDispatch::Response.new(200, { "Content-Type" => "text/xml" })
assert_equal('utf-16', resp.charset)
ensure
ActionDispatch::Response.default_charset = original
end
end
end
class ResponseIntegrationTest < ActionDispatch::IntegrationTest