diff options
author | Akira Matsuda <ronnie@dio.jp> | 2019-07-29 12:58:36 +0900 |
---|---|---|
committer | Akira Matsuda <ronnie@dio.jp> | 2019-07-29 14:17:36 +0900 |
commit | d55dea5ef1cde3172d83f12a7ded96a9603dcaa9 (patch) | |
tree | 00ca4cad113a8530fb02719578a30978e117d23f /actionpack/lib/action_dispatch | |
parent | 62d089a4ad0170320b851addf76f7f48a49d68d8 (diff) | |
download | rails-d55dea5ef1cde3172d83f12a7ded96a9603dcaa9.tar.gz rails-d55dea5ef1cde3172d83f12a7ded96a9603dcaa9.tar.bz2 rails-d55dea5ef1cde3172d83f12a7ded96a9603dcaa9.zip |
Add Mime::Type#match? that doesn't create MatchData
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/http/mime_type.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb index ed1d50f3b9..4bee8ed785 100644 --- a/actionpack/lib/action_dispatch/http/mime_type.rb +++ b/actionpack/lib/action_dispatch/http/mime_type.rb @@ -202,7 +202,7 @@ module Mime # For an input of <tt>'application'</tt>, returns <tt>[Mime[:html], Mime[:js], # Mime[:xml], Mime[:yaml], Mime[:atom], Mime[:json], Mime[:rss], Mime[:url_encoded_form]</tt>. def parse_data_with_trailing_star(type) - Mime::SET.select { |m| m =~ type } + Mime::SET.select { |m| m.match?(type) } end # This method is opposite of register method. @@ -283,6 +283,12 @@ module Mime @synonyms.any? { |synonym| synonym.to_s =~ regexp } || @string =~ regexp end + def match?(mime_type) + return false unless mime_type + regexp = Regexp.new(Regexp.quote(mime_type.to_s)) + @synonyms.any? { |synonym| synonym.to_s.match?(regexp) } || @string.match?(regexp) + end + def html? symbol == :html || @string =~ /html/ end |