diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2012-05-14 21:15:32 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2012-05-14 21:15:32 -0400 |
commit | 65ae23a8fe1b8e5740431497331fecfbd3c8b3fd (patch) | |
tree | 8c04959873026f9c52074afda7fbdb7c927e7421 | |
parent | a652c8f79097392c46ed51760ead2499fa61b45d (diff) | |
download | python-coveragepy-git-65ae23a8fe1b8e5740431497331fecfbd3c8b3fd.tar.gz |
Properly deal with files encoded as UTF-8 with BOM. Fixes #179.
-rw-r--r-- | AUTHORS.txt | 1 | ||||
-rw-r--r-- | CHANGES.txt | 9 | ||||
-rw-r--r-- | coverage/__init__.py | 2 | ||||
-rw-r--r-- | coverage/html.py | 4 | ||||
-rw-r--r-- | coverage/parser.py | 4 |
5 files changed, 19 insertions, 1 deletions
diff --git a/AUTHORS.txt b/AUTHORS.txt index f59ab18b..edb6be94 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -7,6 +7,7 @@ Chris Adams Geoff Bache Titus Brown Brett Cannon +Pablo Carballo Guillaume Chazarain David Christian Danek Duvall diff --git a/CHANGES.txt b/CHANGES.txt index 4a89b3d0..404947f3 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -2,6 +2,15 @@ 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 ---------------------------- diff --git a/coverage/__init__.py b/coverage/__init__.py index b3e79c82..f4e17b29 100644 --- a/coverage/__init__.py +++ b/coverage/__init__.py @@ -5,7 +5,7 @@ http://nedbatchelder.com/code/coverage """ -__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(): diff --git a/coverage/html.py b/coverage/html.py index f39bf949..b0eff5f2 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -148,6 +148,10 @@ class HtmlReporter(Reporter): # 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 diff --git a/coverage/parser.py b/coverage/parser.py index d380eda1..f868d357 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -35,6 +35,10 @@ class CodeParser(object): "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 |