diff options
author | Angelo Capilleri <capilleri@yahoo.com> | 2012-12-22 09:18:01 +0100 |
---|---|---|
committer | Angelo Capilleri <capilleri@yahoo.com> | 2012-12-22 09:18:08 +0100 |
commit | c2267db383fb42e2e3c2abdbd58be6638908fb0f (patch) | |
tree | a8d5e887c6aec323bd45c21f05316022dcf48ed6 /actionpack/lib/action_dispatch | |
parent | f9da785d0b1b22317cfca25c15fb555e9016accb (diff) | |
download | rails-c2267db383fb42e2e3c2abdbd58be6638908fb0f.tar.gz rails-c2267db383fb42e2e3c2abdbd58be6638908fb0f.tar.bz2 rails-c2267db383fb42e2e3c2abdbd58be6638908fb0f.zip |
return Mime::NullType if format is unknown
If a request has an unknown format, the methods html?, xml?, json? ...etc
not raise an Exception.
This patch add a class Mime::NullType, that is returned when request.format is unknown
and it responds false to the methods that ends with '?' and true to 'nil?'.
It refers to #7837, this issue is considered a improvement not a bug.
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/http/mime_type.rb | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb index f56f09c5b3..912da741b7 100644 --- a/actionpack/lib/action_dispatch/http/mime_type.rb +++ b/actionpack/lib/action_dispatch/http/mime_type.rb @@ -27,7 +27,7 @@ module Mime class << self def [](type) return type if type.is_a?(Type) - Type.lookup_by_extension(type) + Type.lookup_by_extension(type) || NullType.new end def fetch(type) @@ -306,6 +306,17 @@ module Mime method.to_s.ends_with? '?' end end + + class NullType + def nil? + true + end + + private + def method_missing(method, *args) + false if method.to_s.ends_with? '?' + end + end end require 'action_dispatch/http/mime_types' |