From 5d860471ac6e14b4ada641eb1c3a5b7c4f3f3940 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Thu, 11 Aug 2016 07:46:53 +0100 Subject: [PATCH] pelican_open: don't raise IndexError on empty files If the file is empty, content[0] raises IndexError. --- pelican/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pelican/utils.py b/pelican/utils.py index 4e729361..06290d16 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -244,7 +244,7 @@ def pelican_open(filename, mode='rb', strip_crs=(sys.platform == 'win32')): with codecs.open(filename, mode, encoding='utf-8') as infile: content = infile.read() - if content[0] == codecs.BOM_UTF8.decode('utf8'): + if content[:1] == codecs.BOM_UTF8.decode('utf8'): content = content[1:] if strip_crs: content = content.replace('\r\n', '\n')