From 92e9f3b31378e4a3d12d5d2c2933b50d7f4c64f1 Mon Sep 17 00:00:00 2001 From: Joseph Reagle Date: Wed, 23 Jan 2013 12:38:29 -0500 Subject: [PATCH] bom detection and removal --- pelican/utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pelican/utils.py b/pelican/utils.py index a761917a..8f9afcc0 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -14,7 +14,7 @@ import fnmatch from collections import defaultdict, Hashable from functools import partial -from codecs import open +from codecs import open, BOM_UTF8 from datetime import datetime from itertools import groupby from jinja2 import Markup @@ -192,7 +192,10 @@ class pelican_open(object): self.filename = filename def __enter__(self): - return open(self.filename, encoding='utf-8').read() + content = open(self.filename, encoding='utf-8').read() + if content[0] == BOM_UTF8.decode('utf8'): + content = content[1:] + return content def __exit__(self, exc_type, exc_value, traceback): pass