提交 f36dafa4 编写于 作者: S Seth Fitzsimmons 提交者: Joshua Peek

Implement Mime::Type.=~ to match all synonyms against arg [#1573 state:resolved]

Signed-off-by: NJoshua Peek <josh@joshpeek.com>
上级 7c185181
......@@ -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)
......
......@@ -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?
......
......@@ -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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册