[CMF-checkins] SVN: CMF/branches/1.6/C Merged r41308 from trunk:

Florent Guillaume fg at nuxeo.com
Fri Jan 13 12:38:23 EST 2006


Log message for revision 41309:
  Merged r41308 from trunk:
  
  Autodetect the encoding of UTF-8 text files with a suitable
  Byte Order Mark (0xEF 0xBB 0xBF).
  

Changed:
  U   CMF/branches/1.6/CHANGES.txt
  U   CMF/branches/1.6/CMFCore/FSFile.py
  A   CMF/branches/1.6/CMFCore/tests/fake_skins/fake_skin/testUtf8.js
  U   CMF/branches/1.6/CMFCore/tests/test_FSFile.py

-=-
Modified: CMF/branches/1.6/CHANGES.txt
===================================================================
--- CMF/branches/1.6/CHANGES.txt	2006-01-13 17:35:47 UTC (rev 41308)
+++ CMF/branches/1.6/CHANGES.txt	2006-01-13 17:38:23 UTC (rev 41309)
@@ -11,6 +11,9 @@
 
     - Back-ported the GenericSetup style of site creation from CMF trunk
 
+    - FSFile: autodetect the encoding of UTF-8 text files with a
+      suitable Byte Order Mark (0xEF 0xBB 0xBF).
+
   Others
 
     - CMFCore utils: Made _checkPermission depend on Zope's checkPermission.

Modified: CMF/branches/1.6/CMFCore/FSFile.py
===================================================================
--- CMF/branches/1.6/CMFCore/FSFile.py	2006-01-13 17:35:47 UTC (rev 41308)
+++ CMF/branches/1.6/CMFCore/FSFile.py	2006-01-13 17:38:23 UTC (rev 41309)
@@ -15,6 +15,7 @@
 $Id$
 """
 
+import codecs
 import Globals
 from AccessControl import ClassSecurityInfo
 from DateTime import DateTime
@@ -79,6 +80,11 @@
                 body = body.data
             content_type, enc=guess_content_type(
                 getattr(file, 'filename',id), body, content_type)
+            if (enc is None
+                and (content_type.startswith('text/') or
+                     content_type.startswith('application/'))
+                and body.startswith(codecs.BOM_UTF8)):
+                content_type += '; charset=utf-8'
 
         return content_type
 

Copied: CMF/branches/1.6/CMFCore/tests/fake_skins/fake_skin/testUtf8.js (from rev 41308, CMF/trunk/CMFCore/tests/fake_skins/fake_skin/testUtf8.js)

Modified: CMF/branches/1.6/CMFCore/tests/test_FSFile.py
===================================================================
--- CMF/branches/1.6/CMFCore/tests/test_FSFile.py	2006-01-13 17:35:47 UTC (rev 41308)
+++ CMF/branches/1.6/CMFCore/tests/test_FSFile.py	2006-01-13 17:38:23 UTC (rev 41309)
@@ -181,7 +181,15 @@
         self.assertEqual( self.RESPONSE.getHeader( 'Last-Modified'.lower() )
                         , rfc1123_date( mod_time ) )
 
+    def test_utf8charset_detection( self ):
+        file_name = 'testUtf8.js'
+        file = self._makeOne(file_name, file_name)
+        file = file.__of__(self.root)
+        data = file.index_html(self.REQUEST, self.RESPONSE)
+        self.assertEqual(self.RESPONSE.getHeader('content-type'),
+                         'application/x-javascript; charset=utf-8')
 
+
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(FSFileTests),



More information about the CMF-checkins mailing list