Skip to content

Commit

Permalink
Merge branch 'master' of [email protected]:rails/rails
Browse files Browse the repository at this point in the history
  • Loading branch information
dhh committed May 1, 2008
2 parents 926f464 + f48e899 commit 12288a0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
9 changes: 6 additions & 3 deletions actionpack/lib/action_controller/mime_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ def parse(accept_header)
# keep track of creation order to keep the subsequent sort stable
list = []
accept_header.split(/,/).each_with_index do |header, index|
params = header.split(/;\s*q=/)
list << AcceptItem.new(index, *params) unless params.empty?
params, q = header.split(/;\s*q=/)
if params
params.strip!
list << AcceptItem.new(index, params, q) unless params.empty?
end
end
list.sort!

Expand Down Expand Up @@ -145,7 +148,7 @@ def ===(list)
end

def ==(mime_type)
return false unless mime_type
return false if mime_type.blank?
(@synonyms + [ self ]).any? do |synonym|
synonym.to_s == mime_type.to_s || synonym.to_sym == mime_type.to_sym
end
Expand Down
7 changes: 7 additions & 0 deletions actionpack/test/controller/mime_type_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ def test_parse_crappy_broken_acceptlines
expect = [Mime::HTML, Mime::XML, "image/*", Mime::TEXT, Mime::ALL]
assert_equal expect, Mime::Type.parse(accept).collect { |c| c.to_s }
end

# Accept header send with user HTTP_USER_AGENT: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1)
def test_parse_crappy_broken_acceptlines2
accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, , pronto/1.00.00, sslvpn/1.00.00.00, */*"
expect = ['image/gif', 'image/x-xbitmap', 'image/jpeg','image/pjpeg', 'application/x-shockwave-flash', 'application/vnd.ms-excel', 'application/vnd.ms-powerpoint', 'application/msword', 'pronto/1.00.00', 'sslvpn/1.00.00.00', Mime::ALL ]
assert_equal expect, Mime::Type.parse(accept).collect { |c| c.to_s }
end

def test_custom_type
Mime::Type.register("image/gif", :gif)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,12 @@ def get_multi(*keys)

results = {}

server_keys.each do |server, keys|
keys = keys.join ' '
server_keys.each do |server, keys_for_server|
keys_for_server = keys_for_server.join ' '
values = if @multithread then
threadsafe_cache_get_multi server, keys
threadsafe_cache_get_multi server, keys_for_server
else
cache_get_multi server, keys
cache_get_multi server, keys_for_server
end
values.each do |key, value|
results[cache_keys[key]] = Marshal.load value
Expand Down

0 comments on commit 12288a0

Please sign in to comment.