diff options
author | Eileen M. Uchitelle <eileencodes@users.noreply.github.com> | 2019-03-19 09:22:16 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-19 09:22:16 -0400 |
commit | 7fe3c69331175a64f01ef64e7afab6d9236fbdbc (patch) | |
tree | d8df19bd0295fe46cd6f311ed47efea016e78bc6 /actionpack/lib/action_dispatch/http | |
parent | 969a1416ebbb74ffb50617ae00029308e8d4f176 (diff) | |
parent | b5e8942c95078945ff09a83b2fc03a0ae7e35953 (diff) | |
download | rails-7fe3c69331175a64f01ef64e7afab6d9236fbdbc.tar.gz rails-7fe3c69331175a64f01ef64e7afab6d9236fbdbc.tar.bz2 rails-7fe3c69331175a64f01ef64e7afab6d9236fbdbc.zip |
Merge pull request #35604 from jhawthorn/validate_mime_types
Raise exception when building invalid mime type
Diffstat (limited to 'actionpack/lib/action_dispatch/http')
-rw-r--r-- | actionpack/lib/action_dispatch/http/mime_type.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb index c3e0ea3c89..296a36ad28 100644 --- a/actionpack/lib/action_dispatch/http/mime_type.rb +++ b/actionpack/lib/action_dispatch/http/mime_type.rb @@ -170,6 +170,7 @@ module Mime def parse(accept_header) if !accept_header.include?(",") accept_header = accept_header.split(PARAMETER_SEPARATOR_REGEXP).first + return [] unless accept_header parse_trailing_star(accept_header) || [Mime::Type.lookup(accept_header)].compact else list, index = [], 0 @@ -221,7 +222,15 @@ module Mime attr_reader :hash + MIME_NAME = "[a-zA-Z0-9][a-zA-Z0-9#{Regexp.escape('!#$&-^_.+')}]{0,126}" + MIME_REGEXP = /\A(?:\*\/\*|#{MIME_NAME}\/(?:\*|#{MIME_NAME}))\z/ + + class InvalidMimeType < StandardError; end + def initialize(string, symbol = nil, synonyms = []) + unless MIME_REGEXP.match?(string) + raise InvalidMimeType, "#{string.inspect} is not a valid MIME type" + end @symbol, @synonyms = symbol, synonyms @string = string @hash = [@string, @synonyms, @symbol].hash |