#2433: paste.util.mimeparse.best_match compatibility with '*' mime type
------------------------+---------------------------------------------------
 Reporter:  amol        |       Owner:            
     Type:  defect      |      Status:  new       
 Priority:  normal      |   Milestone:  2.* bugfix
Component:  TurboGears  |     Version:  2.0.3     
 Severity:  normal      |    Keywords:            
------------------------+---------------------------------------------------
 Copying here the content of email I sent to the TG2 ML as it has been
 asked to me to open a ticket about this issue.

 As RFC 2616 media range in HTTP_ACCEPT should be specified as

  media-range    = ( "*/*"
                        | ( type "/" "*" )
                        | ( type "/" subtype )
                        ) *( ";" parameter )

 so when "all" is meant "*/*" should be passed, but some user agents, like
 the
 facebook external link retriever pass '*' instead of '*/*' this makes
 paste.util.mimeparse.best_match crash on
 paste.util.mimeparse.parse_mime_type

 paste.util.mimeprase.best_match is used by Turbogears to detect which
 template
 to render, and so each TG2 application crashes when contacted by facebook.

 A solution is to change paste.util.mimeparse.parse_mime_type to support
 the
 '*' syntax by adding

    if parts[0].strip() == '*':
        parts[0] = '*/*'

 just before

    (type, subtype) = parts[0].split("/")

 this fixes the problem and I have already patched all my deployed TG2
 apps,
 but I think that a more general fix might be good and also people at paste
 and
 mimeparse might be interested in having the patch. (This happens with
 Paste-1.7.2 at least)

 The working version of the parse_mime_type method is the following one:

 def parse_mime_type(mime_type):
    """Carves up a mime_type and returns a tuple of the
       (type, subtype, params) where 'params' is a dictionary
       of all the parameters for the media range.
       For example, the media range 'application/xhtml;q=0.5' would
       get parsed into:

       ('application', 'xhtml', {'q', '0.5'})
       """
    parts = mime_type.split(";")
    params = dict([tuple([s.strip() for s in param.split("=")])\
            for param in parts[1:] ])
    if parts[0].strip() == '*':
        parts[0] = '*/*'
    (type, subtype) = parts[0].split("/")
    return (type.strip(), subtype.strip(), params)

-- 
Ticket URL: <http://trac.turbogears.org/ticket/2433>
TurboGears <http://www.turbogears.org/>
TurboGears front-to-back web development
-- 
You received this message because you are subscribed to the Google
Groups "TurboGears Tickets" group.
This group is read-only. No posting by normal members allowed.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/turbogears-tickets?hl=en?hl=en

Reply via email to