aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
diff options
context:
space:
mode:
authorAngelo capilleri <capilleri@yahoo.com>2012-10-31 14:25:51 +0100
committerAngelo capilleri <capilleri@yahoo.com>2012-10-31 15:07:37 +0100
commita8560fa361958b33d76e4468eb5c07d82a20196e (patch)
treecb8c582ce21a3a58110bd6430cd74a43204e33d4 /actionpack/lib/action_dispatch
parent65697098811af50a0191a4fce3289b24335f96f9 (diff)
downloadrails-a8560fa361958b33d76e4468eb5c07d82a20196e.tar.gz
rails-a8560fa361958b33d76e4468eb5c07d82a20196e.tar.bz2
rails-a8560fa361958b33d76e4468eb5c07d82a20196e.zip
if format is unknown NullMimeTypeObject is returned
If a unknown format is passed in a request, the methods html?, xml?, json? ...etc Nil Exception. This patch add a class NullMimeTypeObject, that is returned when request.format is unknown and it responds false to the methods that ends with '?'. It refers to #7837, not fixes because it's not considered a improvement not a bug.
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r--actionpack/lib/action_dispatch/http/mime_type.rb13
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 3d560518e1..5ee6f2056e 100644
--- a/actionpack/lib/action_dispatch/http/mime_type.rb
+++ b/actionpack/lib/action_dispatch/http/mime_type.rb
@@ -153,7 +153,7 @@ module Mime
end
def lookup_by_extension(extension)
- EXTENSION_LOOKUP[extension.to_s]
+ EXTENSION_LOOKUP[extension.to_s] || NullMimeTypeObject.new
end
# Registers an alias that's not used on mime type lookup, but can be referenced directly. Especially useful for
@@ -301,6 +301,17 @@ module Mime
method.to_s.ends_with? '?'
end
end
+
+ class NullMimeTypeObject
+ private
+ def method_missing(method, *args)
+ if method.to_s.ends_with? '?'
+ false
+ else
+ super
+ end
+ end
+ end
end
require 'action_dispatch/http/mime_types'