aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2019-03-10 17:30:35 +0900
committerGitHub <noreply@github.com>2019-03-10 17:30:35 +0900
commit08a93efab6bdf10ba7afafb6e51f4b7809c97ebc (patch)
tree50c52dce801175ae192669e2ee99a1037f7ba620 /actionpack/lib
parent0fc13977841d0fb5aa78d5bd86fa9a540477009f (diff)
parent29b42f5e5c80e4397cd02b556f28265ac3e62966 (diff)
downloadrails-08a93efab6bdf10ba7afafb6e51f4b7809c97ebc.tar.gz
rails-08a93efab6bdf10ba7afafb6e51f4b7809c97ebc.tar.bz2
rails-08a93efab6bdf10ba7afafb6e51f4b7809c97ebc.zip
Merge pull request #35549 from r7kamura/feature/response-charset
Support other optional parameters and quoted-strings on Content-Type parser
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_dispatch/http/response.rb7
1 files changed, 3 insertions, 4 deletions
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb
index 1d38942a31..69798f99e0 100644
--- a/actionpack/lib/action_dispatch/http/response.rb
+++ b/actionpack/lib/action_dispatch/http/response.rb
@@ -82,6 +82,7 @@ module ActionDispatch # :nodoc:
SET_COOKIE = "Set-Cookie"
LOCATION = "Location"
NO_CONTENT_CODES = [100, 101, 102, 204, 205, 304]
+ CONTENT_TYPE_PARSER = /\A(?<type>[^;\s]+)?(?:.*;\s*charset=(?<quote>"?)(?<charset>[^;\s]+)\k<quote>)?/ # :nodoc:
cattr_accessor :default_charset, default: "utf-8"
cattr_accessor :default_headers
@@ -409,10 +410,8 @@ module ActionDispatch # :nodoc:
NullContentTypeHeader = ContentTypeHeader.new nil, nil
def parse_content_type(content_type)
- if content_type
- type, charset = content_type.split(/;\s*charset=/)
- type = nil if type && type.empty?
- ContentTypeHeader.new(type, charset)
+ if content_type && match = CONTENT_TYPE_PARSER.match(content_type)
+ ContentTypeHeader.new(match[:type], match[:charset])
else
NullContentTypeHeader
end