From e94147cd3ae55b30ff6b7edd06b8a3b06786724a Mon Sep 17 00:00:00 2001 From: Joseph Reagle Date: Wed, 23 Jan 2013 11:01:13 -0500 Subject: [PATCH] utf-8 bom detection and removal --- pelican/utils.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pelican/utils.py b/pelican/utils.py index cfbc3c23..e4ae8abd 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -184,11 +184,12 @@ def get_date(string): pass raise ValueError("'%s' is not a valid date" % string) - -def pelican_open(path): +def pelican_open(filename): """Open a file and return it's content""" - return open(path, encoding='utf-8').read() - + content = open(filename, encoding='utf-8').read() + if content[0] == codecs.BOM_UTF8.decode('utf8'): + content = content[1:] + return content def slugify(value): """