[Checkins] SVN: zope.contenttype/trunk/ Properly restore the HTML snippet detection, by looking at the entire string and not just its start.

Hanno Schlichting hannosch at hannosch.eu
Wed Jul 27 05:44:18 EDT 2011


Log message for revision 122372:
  Properly restore the HTML snippet detection, by looking at the entire string and not just its start.
  

Changed:
  U   zope.contenttype/trunk/CHANGES.txt
  U   zope.contenttype/trunk/setup.py
  U   zope.contenttype/trunk/src/zope/contenttype/__init__.py
  U   zope.contenttype/trunk/src/zope/contenttype/tests/testContentTypes.py

-=-
Modified: zope.contenttype/trunk/CHANGES.txt
===================================================================
--- zope.contenttype/trunk/CHANGES.txt	2011-07-27 08:47:44 UTC (rev 122371)
+++ zope.contenttype/trunk/CHANGES.txt	2011-07-27 09:44:17 UTC (rev 122372)
@@ -1,9 +1,11 @@
 Change History
 ==============
 
-3.5.5 (unreleased)
+3.5.5 (2011-07-27)
 ------------------
 
+* Properly restore the HTML snippet detection, by looking at the entire string
+  and not just its start.
 
 3.5.4 (2011-07-26)
 ------------------

Modified: zope.contenttype/trunk/setup.py
===================================================================
--- zope.contenttype/trunk/setup.py	2011-07-27 08:47:44 UTC (rev 122371)
+++ zope.contenttype/trunk/setup.py	2011-07-27 09:44:17 UTC (rev 122372)
@@ -37,7 +37,7 @@
 
 setup(
     name='zope.contenttype',
-    version='3.5.5dev',
+    version='3.5.5',
     url='http://pypi.python.org/pypi/zope.contenttype',
     author='Zope Foundation and Contributors',
     author_email='zope-dev at zope.org',

Modified: zope.contenttype/trunk/src/zope/contenttype/__init__.py
===================================================================
--- zope.contenttype/trunk/src/zope/contenttype/__init__.py	2011-07-27 08:47:44 UTC (rev 122371)
+++ zope.contenttype/trunk/src/zope/contenttype/__init__.py	2011-07-27 09:44:17 UTC (rev 122372)
@@ -28,10 +28,9 @@
     """
     # 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('<html>'):
             return 'text/html'
 
@@ -39,10 +38,11 @@
             return 'text/html'
 
         # what about encodings??
-        if s.startswith('<?xml'):
+        if s2.startswith('<?xml'):
             return 'text/xml'
 
-    # we also recognize small snippets of HTML
+    # we also recognize small snippets of HTML - the closing tag might be
+    # anywhere, even at the end of 
     if '</' in s:
         return 'text/html'
 

Modified: zope.contenttype/trunk/src/zope/contenttype/tests/testContentTypes.py
===================================================================
--- zope.contenttype/trunk/src/zope/contenttype/tests/testContentTypes.py	2011-07-27 08:47:44 UTC (rev 122371)
+++ zope.contenttype/trunk/src/zope/contenttype/tests/testContentTypes.py	2011-07-27 09:44:17 UTC (rev 122372)
@@ -72,7 +72,7 @@
         self.assertEqual(text_type('<?xml version="1.0"><foo/>'),
                          'text/xml')
         self.assertEqual(text_type('<?XML version="1.0"><foo/>'),
-                         'text/plain')
+                         'text/xml')
         self.assertEqual(text_type('foo bar'),
                          'text/plain')
         self.assertEqual(text_type('<!DOCTYPE HTML PUBLIC '
@@ -82,6 +82,8 @@
         self.assertEqual(text_type('\n\n<!DOCTYPE html>\n'), 'text/html')
         # we can also parse text snippets
         self.assertEqual(text_type('<p>Hello</p>'), 'text/html')
+        longtext = 'abc ' * 100
+        self.assertEqual(text_type('<p>%s</p>' % longtext), 'text/html')
         # See https://bugs.launchpad.net/bugs/487998
         self.assertEqual(text_type(' ' * 14 + HTML),
                          'text/html')



More information about the checkins mailing list