#58 ✓wontfix
Peter Kieltyka

Post data from Mime::Type results in error

Reported by Peter Kieltyka | June 25th, 2009 @ 04:49 PM

This is an error I came across when using Rails 2.3.2 and Rack 1.0.

What is happening is a closed source client application is connecting to our Rails application and sending a POST with the content-type as "application/xml". When Rack tries to process the request it ends up trying to call the split method on a Mime::Type object and errors. The fix is just adding a .to_s before splitting, here it the process / rational of the request.

  1. POST request to /test with XML data and content-type: application/xml
  2. ActionController::Request parses the request

Note that ActionController::Request inherits from Rack::Request and overrides the content_type method. Rail's method uses Rack's Mime::Type class to lookup if the content-type is a mime-type. Because application/xml is within MIME_TYPES, it will return a Mime::Type object. Eventually the media_type method is called in Rack::Request at which point this line gets executed:

content_type && content_type.split(/\s[;,]\s/, 2).first.downcase

In this case, content_type is a Mime::Type object and does not have the split method, and then fails. My suggestion is to change the line to:

content_type && content_type.to_s.split(/\s[;,]\s/, 2).first.downcase

I've tested this patch in my application and it works and still meets the test specs.

Best regards.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

People watching this ticket

Attachments

Pages