Commits

Ned Batchelder  committed 5440175

Properly deal with files encoded as UTF-8 with BOM. Fixes #179.

  • Participants
  • Parent commits 40c6a72

Comments (0)

Files changed (5)

 Geoff Bache
 Titus Brown
 Brett Cannon
+Pablo Carballo
 Guillaume Chazarain
 David Christian
 Danek Duvall
 Change history for Coverage.py
 ------------------------------
 
+Version 3.5.3b1
+---------------
+
+- Files encoded as UTF-8 with a BOM are now properly handled, fixing
+  `issue 179`_.  Thanks, Pablo Carballo.
+
+.. _issue 179: https://bitbucket.org/ned/coveragepy/issue/179/htmlreporter-fails-when-source-file-is
+
+
 Version 3.5.2 --- 4 May 2012
 ----------------------------
 

File coverage/__init__.py

 
 """
 
-__version__ = "3.5.2"       # see detailed history in CHANGES.txt
+__version__ = "3.5.3b1"       # see detailed history in CHANGES.txt
 
 __url__ = "http://nedbatchelder.com/code/coverage"
 if max(__version__).isalpha():

File coverage/html.py

         # later to properly write the HTML.
         if sys.version_info < (3, 0):
             encoding = source_encoding(source)
+            # Some UTF8 files have the dreaded UTF8 BOM. If so, junk it.
+            if encoding.startswith("utf-8") and source[:3] == "\xef\xbb\xbf":
+                source = source[3:]
+                encoding = "utf-8"
 
         # Get the numbers for this file.
         nums = analysis.numbers

File coverage/parser.py

                     "No source for code: %r: %s" % (self.filename, err)
                     )
 
+        # Scrap the BOM if it exists.
+        if self.text and ord(self.text[0]) == 0xfeff:
+            self.text = self.text[1:]
+
         self.exclude = exclude
 
         self.show_tokens = False