Comment 10 for bug 34758

Revision history for this message
Gavin Panella (allenap) wrote : Re: librarian will set type to text/html though it should be text/plain

The debdiff case was dealt with recently in bug 229040, but it looks like a more general fix is necessary. The problem, afaict, is in the `zope.app.content_types.text_type` function, which does some really awful guessing:

def text_type(s):
    s = s.strip()
    # Yuk. See if we can figure out the type by content.
    if s.lower().startswith('<html>') or '</' in s:
        return 'text/html'
    elif s.startswith('<?xml'):
        return 'text/xml'
    else:
        return 'text/plain'

We could call `z.a.content_types.guess_content_type` with an explicit default, then `text_type` will never be called. Some people may rely on the fact that real XML and HTML files are currently detected, so a refined version of `text_type` may be needed instead.