public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Implement Mime::Type.=~ to match all synonyms against arg [#1573 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
mojodna (author)
Mon Dec 15 10:00:55 -0800 2008
josh (committer)
Mon Dec 15 10:00:55 -0800 2008
commit  f36dafa492e3de66e624d81d6860f5f0536de6b0
tree    17fcb6dbb50c52f5f06ceaab00cf203be17c3dac
parent  7c18518105e98ccfd89fe64194ede27824dfe8b3
...
587
588
589
590
 
591
592
593
...
587
588
589
 
590
591
592
593
0
@@ -587,7 +587,7 @@ module ActionController
0
         def response_from_page_or_rjs()
0
           content_type = @response.content_type
0
 
0
-          if content_type && content_type =~ /text\/javascript/
0
+          if content_type && Mime::JS =~ content_type
0
             body = @response.body.dup
0
             root = HTML::Node.new(nil)
0
 
...
176
177
178
 
 
 
 
 
 
 
 
179
180
181
...
176
177
178
179
180
181
182
183
184
185
186
187
188
189
0
@@ -176,6 +176,14 @@ module Mime
0
       end
0
     end
0
 
0
+    def =~(mime_type)
0
+      return false if mime_type.blank?
0
+      regexp = Regexp.new(mime_type.to_s)
0
+      (@synonyms + [ self ]).any? do |synonym|
0
+        synonym.to_s =~ regexp
0
+      end
0
+    end
0
+
0
     # Returns true if Action Pack should check requests using this Mime Type for possible request forgery.  See
0
     # ActionController::RequestForgeryProtection.
0
     def verify_request?
...
81
82
83
 
 
 
 
 
 
 
 
84
...
81
82
83
84
85
86
87
88
89
90
91
92
0
@@ -81,4 +81,12 @@ class MimeTypeTest < Test::Unit::TestCase
0
     assert verified.each   { |type| assert  Mime.const_get(type.to_s.upcase).verify_request?, "Verifiable Mime Type is not verified: #{type.inspect}" }
0
     assert unverified.each { |type| assert !Mime.const_get(type.to_s.upcase).verify_request?, "Nonverifiable Mime Type is verified: #{type.inspect}" }
0
   end
0
+
0
+  def test_regexp_matcher
0
+    assert Mime::JS =~ "text/javascript"
0
+    assert Mime::JS =~ "application/javascript"
0
+    assert Mime::JS !~ "text/html"
0
+    assert !(Mime::JS !~ "text/javascript")
0
+    assert !(Mime::JS !~ "application/javascript")
0
+  end
0
 end

Comments