Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implement Mime::Type.=~ to match all synonyms against arg [#1573 stat…

…e:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information...
commit f36dafa492e3de66e624d81d6860f5f0536de6b0 1 parent 7c18518
@mojodna mojodna authored josh committed
View
2  actionpack/lib/action_controller/assertions/selector_assertions.rb
@@ -587,7 +587,7 @@ def assert_select_email(&block)
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)
View
8 actionpack/lib/action_controller/mime_type.rb
@@ -176,6 +176,14 @@ def ==(mime_type)
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?
View
8 actionpack/test/controller/mime_type_test.rb
@@ -81,4 +81,12 @@ def test_verifiable_mime_types
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
Please sign in to comment.
Something went wrong with that request. Please try again.