From ea3ac1206a8cc660bfba7f0911abde96c1baf7ad Mon Sep 17 00:00:00 2001 From: Hanno Schlichting Date: Wed, 27 Jul 2011 09:44:17 +0000 Subject: Properly restore the HTML snippet detection, by looking at the entire string and not just its start. --- src/zope/contenttype/__init__.py | 10 +++++----- src/zope/contenttype/tests/testContentTypes.py | 4 +++- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/zope/contenttype/__init__.py b/src/zope/contenttype/__init__.py index 1b42fd6..c0a26ec 100644 --- a/src/zope/contenttype/__init__.py +++ b/src/zope/contenttype/__init__.py @@ -28,10 +28,9 @@ def text_type(s): """ # at least the maximum length of any tags we look for max_tags = 14 - s = s.strip()[:max_tags] - s2 = s.lower() + s2 = s.strip()[:max_tags].lower() - if len(s) == max_tags: + if len(s2) == max_tags: if s2.startswith(''): return 'text/html' @@ -39,10 +38,11 @@ def text_type(s): return 'text/html' # what about encodings?? - if s.startswith(''), 'text/xml') self.assertEqual(text_type(''), - 'text/plain') + 'text/xml') self.assertEqual(text_type('foo bar'), 'text/plain') self.assertEqual(text_type('\n'), 'text/html') # we can also parse text snippets self.assertEqual(text_type('

Hello

'), 'text/html') + longtext = 'abc ' * 100 + self.assertEqual(text_type('

%s

' % longtext), 'text/html') # See https://bugs.launchpad.net/bugs/487998 self.assertEqual(text_type(' ' * 14 + HTML), 'text/html') -- cgit v1.2.1