Changeset 6484
- Timestamp:
- 03/28/07 16:42:21 (1 year ago)
- Files:
-
- trunk/actionpack/lib/action_controller/mime_type.rb (modified) (1 diff)
- trunk/actionpack/test/controller/mime_type_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/lib/action_controller/mime_type.rb
r6350 r6484 64 64 def parse(accept_header) 65 65 # keep track of creation order to keep the subsequent sort stable 66 index = 0 67 list = accept_header.split(/,/).map! do |i| 68 AcceptItem.new(index += 1, *i.split(/;\s*q=/)) 69 end.sort! 66 list = [] 67 accept_header.split(/,/).each_with_index do |header, index| 68 params = header.split(/;\s*q=/) 69 list << AcceptItem.new(index, *params) unless params.empty? 70 end 71 list.sort! 70 72 71 73 # Take care of the broken text/xml entry by renaming or deleting it trunk/actionpack/test/controller/mime_type_test.rb
r6153 r6484 21 21 expect = [Mime::HTML, Mime::XML, Mime::PNG, Mime::PDF, Mime::TEXT, Mime::YAML, Mime::ALL] 22 22 assert_equal expect, Mime::Type.parse(accept) 23 end 24 25 # Accept header send with user HTTP_USER_AGENT: Sunrise/0.42j (Windows XP) 26 def test_parse_crappy_broken_acceptlines 27 accept = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/*,,*/*;q=0.5" 28 expect = [Mime::HTML, Mime::XML, "image/*", Mime::TEXT, Mime::ALL] 29 assert_equal expect, Mime::Type.parse(accept).collect { |c| c.to_s } 23 30 end 24 31