diff options
author | Seth Fitzsimmons <seth@mojodna.net> | 2008-12-15 12:00:55 -0600 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2008-12-15 12:00:55 -0600 |
commit | f36dafa492e3de66e624d81d6860f5f0536de6b0 (patch) | |
tree | 17fcb6dbb50c52f5f06ceaab00cf203be17c3dac /actionpack | |
parent | 7c18518105e98ccfd89fe64194ede27824dfe8b3 (diff) | |
download | rails-f36dafa492e3de66e624d81d6860f5f0536de6b0.tar.gz rails-f36dafa492e3de66e624d81d6860f5f0536de6b0.tar.bz2 rails-f36dafa492e3de66e624d81d6860f5f0536de6b0.zip |
Implement Mime::Type.=~ to match all synonyms against arg [#1573 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_controller/assertions/selector_assertions.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/mime_type.rb | 8 | ||||
-rw-r--r-- | actionpack/test/controller/mime_type_test.rb | 8 |
3 files changed, 17 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/assertions/selector_assertions.rb b/actionpack/lib/action_controller/assertions/selector_assertions.rb index e03fed7abb..248ca85994 100644 --- a/actionpack/lib/action_controller/assertions/selector_assertions.rb +++ b/actionpack/lib/action_controller/assertions/selector_assertions.rb @@ -587,7 +587,7 @@ module ActionController def response_from_page_or_rjs() content_type = @response.content_type - if content_type && content_type =~ /text\/javascript/ + if content_type && Mime::JS =~ content_type body = @response.body.dup root = HTML::Node.new(nil) diff --git a/actionpack/lib/action_controller/mime_type.rb b/actionpack/lib/action_controller/mime_type.rb index 6923a13f3f..43b3da8d35 100644 --- a/actionpack/lib/action_controller/mime_type.rb +++ b/actionpack/lib/action_controller/mime_type.rb @@ -176,6 +176,14 @@ module Mime end end + def =~(mime_type) + return false if mime_type.blank? + regexp = Regexp.new(mime_type.to_s) + (@synonyms + [ self ]).any? do |synonym| + synonym.to_s =~ regexp + end + end + # Returns true if Action Pack should check requests using this Mime Type for possible request forgery. See # ActionController::RequestForgeryProtection. def verify_request? diff --git a/actionpack/test/controller/mime_type_test.rb b/actionpack/test/controller/mime_type_test.rb index 21ae0419f1..9c4416ecf0 100644 --- a/actionpack/test/controller/mime_type_test.rb +++ b/actionpack/test/controller/mime_type_test.rb @@ -81,4 +81,12 @@ class MimeTypeTest < Test::Unit::TestCase assert verified.each { |type| assert Mime.const_get(type.to_s.upcase).verify_request?, "Verifiable Mime Type is not verified: #{type.inspect}" } assert unverified.each { |type| assert !Mime.const_get(type.to_s.upcase).verify_request?, "Nonverifiable Mime Type is verified: #{type.inspect}" } end + + def test_regexp_matcher + assert Mime::JS =~ "text/javascript" + assert Mime::JS =~ "application/javascript" + assert Mime::JS !~ "text/html" + assert !(Mime::JS !~ "text/javascript") + assert !(Mime::JS !~ "application/javascript") + end end |