From 8301969df9fd76bcde140f310300349b609e2b10 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 8 Sep 2015 15:55:10 -0700 Subject: handle implicit rendering correctly If someone sets just a charset, but depends on the implicit type from rendering, this will store a strange content type header that looks like this: `; charset=blah`. This is so that when the content type header is parsed again, it will return nil for the actual type. --- actionpack/lib/action_dispatch/http/response.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_dispatch/http') diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index d6b6ef2cff..8efc905384 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -208,7 +208,7 @@ module ActionDispatch # :nodoc: if false == charset set_header CONTENT_TYPE, header_info.mime_type else - content_type = header_info.mime_type || Mime::TEXT.to_s + content_type = header_info.mime_type set_content_type content_type, charset || self.class.default_charset end end @@ -322,6 +322,7 @@ module ActionDispatch # :nodoc: def parse_content_type(content_type) if content_type type, charset = content_type.split(/;\s*charset=/) + type = nil if type.empty? ContentTypeHeader.new(type, charset) else ContentTypeHeader.new(nil, nil) @@ -329,7 +330,7 @@ module ActionDispatch # :nodoc: end def set_content_type(content_type, charset) - type = content_type.dup + type = (content_type || '').dup type << "; charset=#{charset}" if charset set_header CONTENT_TYPE, type end @@ -356,7 +357,7 @@ module ActionDispatch # :nodoc: end def assign_default_content_type_and_charset! - return if get_header(CONTENT_TYPE).present? + return if content_type ct = parse_content_type get_header(CONTENT_TYPE) set_content_type(ct.mime_type || Mime::HTML.to_s, -- cgit v1.2.3